- Opening of forms, by adding a JScript Web Resource to the form and then having it run OnLoad.
- Saving of records on forms, by adding a JScript Web Resource to the form and then having it run OnSave.
- On a field changing, by by adding a JScript Web Resource to the form and then having it run on the field’s OnChange event.
- Xrm.Page.data.entity attribute.addOnChange for attributes changing
- Xrm.Page.data.entity.addOnSave for the form save event
- In the lookup control addPreSearch
You can add up to 50 script web resources to a form.
If libraries contain functions with the same name, the function that loads last will be the the one used. To get around this, you can either use unique function names, or use namespaces to differentiate your functions.
Microsoft recommends using jQuery for cross-browser manipulation of the DOM. However, they do not recommend it not support within form scripts and ribbon commands.
Xrm.Page and Xrm.Utility
Xrm.Page is for interacting with form elements. Using Xrm.Page you can get and set field values, show and hide fields, manipulate navigation, interact with a business process flow via Xml.Page.data.process.
Xrm.Page.Context provides ways to retrieve information specific to an organization. This includes what type of device is being used, the client URL, if autosave is enabled for the org, the user id, user name and user roles, query string parameters, and the version.
Xrm.Page.Data provides a way to save and refresh the form.
Xrm.Page.Data.Entity provides ways to retrieve data regarding the form record, such as a collection of the attributes, an XML representation of the saved record, the entity name, the GUID of the record, get the primary attribute, save the record and add/remove to the save event handlers. You can then access Xml.Page.Data.Entity.Attributes to gain access to attribute information such as the name, isdirty, length, control, required level, etc.
Xml.Page.ui gives you access to the control object, including get/set, label, type, and also ability to close the form, tabs on the form, controls on the form, sections, quick forms, navigation.
Xrm.Utility contains functionality such as opening forms and resources, displaying messages to users.
Xrm.Mobile.offline contains methods for is offline enabled, and CRUD mobile operations.
Grid contains methods to change the grid view (setCurrentView), get references to data displayed in the grid, set event handlers for when the grid is loaded (addOnLoad), get selected rows, get the grid entity. For editable grids, there are methods for OnRecordSelect, OnChange and OnSave.
Web Service Calls
- Using jQuery’s $.ajax (which is a wrapper for XMLHttpRequest)
- SDK.REST – a reusable library that simplifies asynchronous data operations using the REST endpoint
- SDK.jQuery – a reusable library that performs actions with the REST endpoint using jQuery
Note the endpoints when accessing Dynamics 365:
- WebAPI – uses JSON, more lightweight than XML. Has OAuth authentication, and OData (a standard for RESTful web services), making it easy to code across multiple languages. Supports FetchXML queries.
- 2011 SOAP endpoint – Older endpoint. Uses XML. Developers use the libraries above provided by Microsoft to interact with the endpoint
- 2011 REST endpoint (deprecated)