Form scripting customizations
Part 10 of "11 things to know about customization"
There are many advantages to implementing customizations to occur on a user's computer. These customizations are faster because they do not require a round trip to the server before they are applied. Form scripting is the way to achieve this in Microsoft Dynamics CRM Online.
Events
Microsoft Dynamics CRM Online supports two events on every entity form: OnLoad and OnSave.
The OnChange event is available on every field in the form.
This means that you can include logic within the form when it loads, when a user saves, or when the value of a field changes.
Adding scripts
You paste your scripts into the definition of the entity forms. Scripts then become part of the entity metadata, and can be exported and imported to another system alongside all the other customizations.
Caution
You should have a thorough knowledge of JScript programming syntax and an understanding of DHTML before you add scripts, and should test your scripts before you publish customizations. Malformed scripts can prevent the form from working correctly.
Add or edit an event-based script to a form- In the Navigation Pane, click Settings, click Customization, and then click Customize Entities.
- Open the entity, click Forms and Views, and then click Form.
- On the More Actions menu, click Edit.
- In the Common Tasks area, click Form Properties.
- On the Events tab, click onSave or OnLoad, and then click Edit.
- In the Event Detail Properties dialog box, on the Details tab, select the Event is enabled check box to enable the event, and in the text box, enter the body of the script that you want to use when the selected event is run.
- For more information, see "Add an event-based script to a form" in the Help topic "Edit Entity forms".
Add or edit an event-based script to a field- In the Navigation Pane, click Settings, click Customization, and then click Customize Entities.
- Open the entity, click Forms and Views, and then click Form.
- On the More Actions menu, click Edit.
- Select a field on the form.
- Click Change Properties.
- On the Events tab, select onChange, and then click Edit.
- In the Event Detail Properties dialog box, on the Details tab, select the Event is enabled check box to enable the event, and in the text box, enter the body of the script that you want to use when the onChange event is run.
- For more information, see "Add an event-based script to a field" in the Help topic "Edit Entity forms".
Note
When you use an event-based script or custom code that refers to specific fields, you should set these fields as dependent fields so that they cannot be deleted from forms. The Event Detail Properties dialog box provides a Dependencies tab where you can add any fields referenced in your script for the event.
The scripting language is JScript, which is functionally equivalent to JavaScript and is well known by many Web developers. For each event, a developer can interact with an object model in the form. This object model is documented in the Microsoft Dynamics CRM Software Development Kit. See Client-side Scripting (Microsoft Dynamics CRM SDK), which describes how a developer can access different properties and methods on the forms.
Form object model
Microsoft Dynamics CRM Online supports using the objects and methods that are provided by Microsoft Dynamics CRM Online. But, because Microsoft Dynamics CRM Online uses Internet Explorer to show the pages, developers can do almost anything that they usually do in a Web application. They can call a Web service or work with another application displayed in an IFrame.
The important thing to avoid in form scripting is referencing any of the HTML elements of the Microsoft Dynamics CRM Online pages that are not documented in the Microsoft Dynamics CRM Software Development Kit. The only supported elements in the pages that can be programmatically referenced or manipulated are documented in this guide. You might not be able to upgrade your customizations to a future version of Microsoft Dynamics CRM Online if you reference unsupported elements or functions because they might not exist in the next version. For more information about things to avoid in form scripting and why, see Unsupported scripting in the Microsoft Dynamics CRM Online Team Blog.
Microsoft Dynamics CRM Online Web services
Microsoft Dynamics CRM Online supports calling Microsoft Dynamics CRM Online Web services directly from client-side code, whether that code is associated with a form event or with JScript configured in an ISV.Config button or menu item. These Web service calls work for both the Microsoft Dynamics CRM Online Web application and Microsoft Dynamics CRM Online for Microsoft Office Outlook. While you are offline with Microsoft Dynamics CRM Online for Outlook, the local Web services are used. The Microsoft Dynamics CRM Software Development Kit documents functions developers can use to help craft the XMLHTTP requests used to call these Web services.
Related Links
Part 11: Supported customizations
Unsupported scripting