Xrm.Utility Reference
The Xrm.Utility object provides a container for useful functions not directly related to the current page.
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.
Functions
The following table lists the functions of Xrm.Utility.
Function | Description |
---|---|
openEntityForm | Opens an entity form. |
openWebResource | Opens an HTML web resource. |
openEntityForm
Opens an entity form.
Xrm.Utility.openEntityForm(name,id,parameters)
Parameters
-
name
- Type: String
- Required: The logical name of an entity.
-
id
- Type: String
- Optional: 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: Object
- Optional: 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.
Return Value: Window object.
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, and Dialogs 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: String
- Required: The name of the HTML web resource to open.
-
webResourceData
- Type: String
- Optional: Data to be passed into the data parameter.
-
width
- Type: Number
- Optional: The width of the window to open in pixels.
-
height
- Type: Number
- Optional: 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 webResourceNameparameter.
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:
Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033");
For more information, see Passing Parameters to HTML Web Resources .
Open an HTML web resource, setting the height and width:
Xrm.Utility.openWebResource("new_webResource.htm", null, 300,300);