Tuesday, November 6, 2012

Xrm.Utility

Well, I was not aware of this new object created by Microsoft, since Microsoft Dynamics CRM 2011 Update Rollup 8. (http://msdn.microsoft.com/en-us/library/jj602956.aspx)

It has 2 function (both open a new browser window) called:

openEntityForm 
  Xrm.Utility.openEntityForm(name,id,parameters) 

Examples:
Open a new account record
Xrm.Utility.openEntityForm("account");
Open an existing account record
Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410");

Open a new account record with a specific form and setting default values
var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);
Open a new contact record, move it to the top left corner of the screen, and set the size of the window 
NoteYou cannot use window object methods such as moveTo or resizeTo in scripts that will run in Microsoft Dynamics CRM for Microsoft Office Outlook.
var newWindow = Xrm.Utility.openEntityForm("contact");
newWindow.moveTo(0,0);
newWindow.resizeTo(800,600);
openWebResource

    Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)
Examples:
Open an HTML web resource named “new_webResource.htm”:Xrm.Utility.openWebResource("new_webResource.htm");
Open an HTML web resource including a single item of data for the data parameter”Xrm.Utility.openWebResource("new_webResource.htm","dataItemValue");
Open an HTML web resource passing multiple values through the data parameter
var customParameters = encodeURIComponent("first=First Value&second=Second Value&third=Third Value"); Xrm.Utility.openWebResource("new_webResource.htm",customParameters); 
NoteThese values have to be extracted from the value of the data parameter in the HTML web resource. For more information, see Sample: Pass Multiple Values to a Web Resource Through the Data Parameter.
Open an HTML web resource with the parameters expected by HTML web resources:
Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033");