Share via


Jscripts snippets for CRM 2011

I have tried to outline couple of examples that you could use in CRM. These examples are based on Xrm patterns which tells you how you can utilize the resources available in better way. These are newly introduced in CRM 2011. The whole idea is to put together a set of common functions as an library which can be used across the forms. You just need to register them under one common place called web resources and keep attaching them to forms where you need to use these. I will also demonstrate how you can achieve that. Let's get to the list and see what we have in store for today :)

  • Server URL.

Xrm.Page.context.getServerUrl()

  • Get the string value of a text field

function GetMainPhone() {
   var MainPhone = Xrm.Page.data.entity.attributes
     .get("telephone1").getValue();
}

  • Set the value of a string field

function SetMainPhone() {
  Xrm.Page.data.entity.attributes
     .get("telephone1").setValue();
}

  • Adding value to option set

var optionsetbox = Xrm.Page.getControl("customertypecode")
optionsetbox.text= "Apurv";
optionsetbox.value= "10";
Xrm.Page.ui.controls.get("customertypecode").addOption(optionsetbox,12);

  • Removing a value from option set on fly

Xrm.Page.getControl("customertypecode").removeOption(4);

I'm still working on more user friendly examples. Please do wait for more. Keep surfing and visiting.

Cheers,
Apurv

Comments

  • Anonymous
    November 21, 2011
    Hi Apurv,As SDK Sample provides quite nice library, whty don't you prensent it with actual scenario??
  • Anonymous
    November 21, 2011
    Hi Kenichiro,I'm building some more examples. Will come up with that soon :)
  • Anonymous
    November 22, 2011
    Master piece, I realy feel lucky to see such a wonderful article that is <a href="www.mlfhardwoodflooringltd.ca ">hardwood floor refinishing toronto</a> what i want.
  • Anonymous
    November 24, 2011
    Great Job Apurv , looking forward for more posts like this ...