Write Code for Microsoft Dynamics CRM Forms
Form programming provides ways to interact with entity forms by using JScript that is executed for events that occur on the form.
In This Topic
When to Use Form Programming
Microsoft Dynamics CRM provides many options to control business processes. Form programming is one option. The primary advantage of form programming is that it is immediate. It does not require data to be submitted to the server and, therefore, provides the best performance for many scenarios. Because it allows for human interaction, it is also the most flexible option.
Tasks frequently performed by using form programming include the following:
Process enhancement and enforcement
Whenever possible, you should perform validation of data while the data is being edited. The definition of the Form field will perform the most common data validation for you. For example, a Single Line of Text field formatted for an email address will not allow an invalid value to be entered into it.
Use form programming for additional validation of data that is unique to your organization. For example, your organization may have specific rules about how telephone numbers should be formatted or a minimum length for the Subject field in a service activity.
You can achieve significant productivity enhancements when you use form scripting to automate common tasks. You can set field values that depend on the data that is entered into a form, that will help save users considerable time when entering data. Using form programming for automation is valuable because it lets the user verify that a standard process is valid in a particular case. Users can make necessary adjustments before saving a record.
Process Enhancement and Enforcement
You can customize the data to display or the layout of the form to optimize the form for specific tasks in your organization’s processes. You can use form programming to show or hide specific form elements, or to open different forms that have been defined for an entity. You can control which fields are required based on data present in the form or in related records.
Factors to Consider When You Use Form Programming
The logic applied in form programming can only be executed in the browser of someone interacting within the Microsoft Dynamics CRM application entity form. Because of this, you should not rely solely on form programming to initiate or enforce processes related to your data. Records can be created or updated directly through the Web service APIs or through workflows outside the context of the form. Form programming should complement business logic applied by using plugins and workflows so that all records created or updated in any manner will comply with the same processes.
While form programming provides capabilities to hide form fields so that users may not be able to view or update some entity data, it does not represent a complete solution for enforcing security requirements. A user can see entity data that is not visible on the form by using a variety of methods, such as Advanced Find or sometimes by just printing a form. For more information, see The Security Model of Microsoft Dynamics CRM.
Different Form Presentations
There are several different ways that forms are presented. These affect the type of code or available events you can use for each. For more information, see Design Considerations for Different Form Presentations. Some new form presentations have been released with update rollups.
- Read Optimized Forms
- Added in Microsoft Dynamics CRM 2011 Update Rollup 7, read-optimized forms do not allow editing of entity records and only a few Xrm.Page object model methods are available for use by web resources that can be displayed in the form. Adding certain form event handlers will cause the forms to revert to the default editable experience. For more information, see Read-Optimized Forms.
- Updated Forms
- Added in Microsoft Dynamics CRM December 2012 Service Update, these forms provided an updated user experience and allow editing, but not all parts of the Xrm.Page object model is available. Adding any form event handlers will cause the form to revert to the default editable experience. For more information, see Updated Forms.
Use the Xrm.Page Script Library Template
The Xrm.Page Script Library Template provides a Microsoft Visual Studio extension you can use to create a project that will help you write form scripts that use the Xrm.Page object in Microsoft Dynamics CRM forms. The Xrm.Page Script Library Template provides the following capbilties:
Capabilities to perform initial testing outside of Microsoft Dynamics CRM without creating a Web resource.
The Xrm.Page Script Library Template is included in the SDK download files at
SDK\Templates\Xrm.PageScriptProjectTemplate. The Readme.docx file at that location provides a description of how to install and use this template.
Use of jQuery
Do not use jQuery to interact with Microsoft Dynamics CRM 2011 forms. Use the Xrm.Page object model methods to access form elements.
The only supported use of jQuery in the Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online web application is to use the jQuery.ajax method to retrieve data from the REST endpoint. For more information, see Using jQuery. Using jQuery to modify Microsoft Dynamics CRM 2011 application pages or forms is not supported. You may use jQuery within your own HTML web resource pages.
ConceptsForm Scripting Quick Reference
JScript Libraries for Microsoft Dynamics CRM
Use Form and Field Events
Use the Xrm.Page Object Model
Use Execution Context and the Form Event Pipeline
Use an IFRAME and Web Resource Controls on a Form
Use the REST Endpoint with Ajax and JScript Web Resources
Other ResourcesWrite Client Application Extensions
Customize Microsoft Dynamics CRM
Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2012 Microsoft Corporation. All rights reserved.