In this blog I am going to give you a brief explanation about how to use JavaScript libraries at the form level as well as how to create new JavaScript libraries in Microsoft Dynamics CRM 2013 and 2015.

To use JavaScript library at the form level follow the steps outlined below:

1. Login to CRM then go to Settings=>Customization=>Customize the system.

2. Inside solution select entity and click on forms

clip_image001

3. Click on Main form

clip_image003

4. Inside form click on Form Properties in Ribbon Bar

image

5. Once you click on Form Properties a new window opens. In that window click on the Event Tab

clip_image007

6. The event tab shows all of the JavaScript libraries related to the form. To add a new JavaScript library click on Add.

clip_image008

7. After clicking on add a new window opens. If you already have the JavaScript file in the CRM system, search for that file and click on Add, otherwise click on New.

image

8. After clicking on the New button another window opens. Fill in all of the information in that window, then select save and publish. This process creates a new web resource in the system.

image

9. To add your code for this JavaScript web resource click on Text editor and copy all of the JavaScript code inside the Text Editor. Or you can upload your JavaScript file here as well, by clicking on the browse button and browsing for your file, once you're done click on Save then Publish button and close record.

10. After this on Form Properties you can see that your new web resource is listed under form Libraries.

image

11. To add JavaScript functions on the form we can call those functions on respective events like OnLoad, On Save and OnChange. On Load and On Save are set with respect to forms while on Change can be set with respect to fields, Tabs of the form.

12. For example to call an event for OnLoad of the form go to Control select form then set event to “OnLoad” and click on Add.

image

13. Once you click on Add, from library drop down Select your library (same library which contains your JavaScript code) and write your function name inside function field and click on OK.

Figure 1: This example is for OnSave type of event.

This example is for OnSave type of event.

14. To call an event on OnChange of fields go to control select name of the field and click on Add, After this repeat step 13

image

Once its done close form properties, save and Publish CRM form.

 For more information about this blog or C5 Insight, contact us here!