Getting Started with Javascript Form Scripting for Microsoft Dynamics CRM 2011

By - October 25, 2012

With the flexibility of Microsoft Dynamics CRM 2011, there are many options for enhancing the product such as data validation, automation and function enhancement. These options require a tool to program the desired action and a technical knowledge of the tool.

For those who are new to Javascript or coding in general, this post will help you get started into Javascript form scripting for Microsoft Dynamics CRM 2011.

In this example, I will show you how to disable a field called Credit Limit on the Contact form using Javascript script.

Please note you can only customize the form using Javascript if you have the correct security role to do it.

1. Click on Customize Tab at the top of the Contact record.

2. Click on Form.

3. Click on Form Properties button in the Ribbon.

4. Click Add. Then Click on New

 

5. Give your Webresource a name, display name, and description. For type, select Script(Jscript) from the dropdown field.

6. Click on Text Editor

7.  Paste the Javascript below in the Editor. Click Ok.

function DisableCreditLimit ()

{

Xrm.Page.getControl(“Creditlimit”).setDisabled(true);

}

When done, your Editor should look similar to this:

8. Next, we add our Webresource that was created in the form libraries.

9. Add the webresource to the OnLoad event, Click Ok.

10. Find our Webrsource name from the Library dropdown. Call our function name (highlighted) in the Handler Properties then click Ok.

function DisableCreditLimit ()

{

Xrm.Page.getControl(“Creditlimit”).setDisabled(true);

}

 

11. Save & Publish.

The results:

Before: Without any Javascript Codes

The field Credit Limit is now grey out due to our Javascript code and is read-only.

While this is a very simple Javascript code and function, Javascript is very useful when Out-of-the-Box functions are not enough to meet your business requirements.  For the CRM enthusiasts who want to learn how Javascript can enhance Microsoft Dynamics CRM forms. Here is a Quick Reference Guide for Form Scripting.

If you rather not tackle these function changes on your own or have questions about JavaScripting for your Microsoft Dynamics CRM system, RSM offers a full range of services from implementation and optimization to development and support.  Contact our professionals for more information on our services at 855.437.7202 or crm@mcgladrey.com.

By: Hien Tieu – New Jersey Microsoft Dynamics CRM Partner

 

Receive Posts by Email

Subscribe and receive notifications of new posts by email.