Published: January 1, 2008
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.
|
|
Events |
|
|
Adding scripts |
|
|
Form object model |
|
|
Microsoft Dynamics CRM Web services |
Microsoft Dynamics CRM 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.
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.
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 SDK. See Client-side Scripting (Microsoft Dynamics CRM SDK), which describes how a developer can access different properties and methods on the forms.
Microsoft Dynamics CRM supports using the objects and methods that are provided by Microsoft Dynamics CRM. But, because Microsoft Dynamics CRM 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 pages that are not documented in the Microsoft Dynamics CRM SDK. 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 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 Team Blog.
Microsoft Dynamics CRM supports calling Microsoft Dynamics CRM 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 Web application and Microsoft Dynamics CRM for Microsoft Office Outlook. While you are offline with Microsoft Dynamics CRM for Outlook, the local Web services are used. The Microsoft Dynamics CRM SDK documents functions developers can use to help craft the XMLHTTP requests used to call these Web services.
Note
The ability to call Microsoft Dynamics CRM Web services using JScript from client-side code addresses many scenarios for Microsoft Dynamics CRM Online. However, the on-premises version of Microsoft Dynamics CRM allows for managed code to be used directly on the server or the Microsoft Dynamics CRM for Outlook client. Because managed code written in C# or Visual Basic .NET is strongly typed, developers creating solutions that call Microsoft Dynamics CRM Web services should consider creating their own Web services that use managed code instead of calling Microsoft Dynamics CRM Web services using JScript directly from client-side code. It is generally easier to develop, test, and maintain solutions that use managed code than JScript.