Xrm.Utility Reference
The Xrm.Utility object provides a container for useful functions not directly related to the current page. This object was added in Microsoft Dynamics CRM 2011 Update Rollup 8.
These functions are available in every application page that supports scripting. You can use them in form scripts or in ribbon commands. For HTML web resources, they are available when you include the ClientGlobalContext.js.aspx page. For more information, see ClientGlobalContext.js.aspx.
The following table lists the functions of Xrm.Utility.
| Function | Description |
|---|---|
|
Opens an entity form. |
|
|
Opens an HTML web resource. |
openEntityForm
Opens an entity form.
Xrm.Utility.openEntityForm(name,id,parameters)
Parameters
- name
- Type: StringRequired: The logical name of an entity.
- id
- Type: StringOptional: The string representation of a unique identifier or the record to open in the form. If not set, a form to create a new record is opened.
- parameters
-
Type: ObjectOptional: A dictionary object that passes extra query string parameters to the form. Invalid query string parameters will cause an error.
Valid extra query string parameters are:
- Form id: To set the id value of the form to use when more than one form is available. The parameter is formid.
- Default field ids: To set default values for a new record form. For more information, see Set Field Values Using Parameters Passed to a Form.
- Custom query string parameters: A form can be configured to accept custom query string parameters. For more information, see Configure a Form to Accept Custom Querystring Parameters.
- Form id: To set the id value of the form to use when more than one form is available. The parameter is formid.
Return Value: Boolean. True if the operation is successful, otherwise false.
Remarks: This function provides a better developer experience than the process of manipulating the URL passed to the window.open method described in Open Forms, Views, Dialogs and Reports with a URL. Using this function also helps ensure that users are not prompted to log in again under certain circumstances.
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
-
Note You 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
Opens an HTML web resource.
Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)
Parameters
- webResourceName
- Type: StringRequired: The name of the HTML web resource to open.
- webResourceData
- Type: StringOptional: Data to be passed into the data parameter.
- width
- Type: NumberOptional: The width of the window to open in pixels.
- height
- Type: NumberOptional: The height of the window to open in pixels.
Return Value: Window object.
Remarks: An HTML web resource can accept the parameter values described in Passing Parameters to HTML Web Resources. This function only provides for passing in the optional data parameter. To pass values for the other valid parameters, you must append them to the webResourceName parameter.
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);
Note These 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
-
For more information, see Passing Parameters to HTML Web Resources.
Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033");
- Open an HTML web resource, setting the height and width
-
Xrm.Utility.openWebResource("new_webResource.htm", null, 300,300);
Concepts
Open Forms, Views, Dialogs and Reports with a URLSet Field Values Using Parameters Passed to a Form
Configure a Form to Accept Custom Querystring Parameters
Form Scripting Quick Reference
Write Code for Microsoft Dynamics CRM Forms
Use the Xrm.Page Object Model
Other Resources
Client-Side Programming ReferenceMicrosoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.