In addition to triggering code to run after specific events occur, Microsoft Dynamics CRM provides an object model of form elements that can be utilized to manipulate data, change form object properties, or analyze the current state of the form or data within the form. This object model is called Xrm.Page and in addition to the event handlers are the primary tool used to develop custom business logic at the client-side.
Some benefits of using the Xrm.Page model are:
- Change the appearance or manipulate form objects like data controls (text boxes, checkboxes, etc.), tabs, sections, etc.
- Identify elements to show/hide.
- Specify names of objects from which to retrieve/store data values.
- Provide namespaces to properties so the system allows multiple controls per field or multiple forms per entity.
The Xrm.Page model provides a namespace container for following objects:
Context provides methods to retrieve information specific to an organization, a user, or parameters that were passed to the form in a query string by event handler registered on Form.
The context object is used in forms by using the Xrm.Page.context syntax. There are several functions that are accessible through the context object, such as getUserId. The following code will return the current user’s UserId.
Data provides access to the data on Entity Form. Values can get or set fields on CRM form after data validation or data manipulation.
The following code will return the value of the email address field:
Or, a shortcut for this code is:
The following code will set the value of the email address field:
UI provides methods to retrieve information about the user interface, collections for several sub components of the form. It provides access to each control present on the form.
The following code will close the current form:
This code will get the value of the associated label of the email address field.
The CRM Xrm.Page Object Model is very broad. Further documentation regarding its capabilities can be found in the Microsoft Dynamics CRM SDK or using the following resources: