SnapShot! 3.0 JavaScript Events

The Dynamics CRM 2011/2013 object model allows you to define events using configuration, through the user-interface, or via code, using JavaScript. In some cases, mostly dependent on your requirements and coding-style, it is advantageous to switch from the normal user interface-configuration to using JavaScript.

One reason to do this is to centralize your event management. By having all of the events in one place, it is easier to make modifications to the event chain.

Here is how events are normally configured:

OnLoad Events



OnSave Events



OnChange Events



Generated JavaScript

And here is what happens when you use the SnapShot! Generate JavaScript Events feature found in the Developer Tools section:

All of the events are extracted from the form and the resulting JavaScript looks like this:

// Entity:    account
// Form:    Information (Main)
function form_OnLoad() {; // new_account_main.js 

    Xrm.Page.getAttribute("websiteurl").addOnChange(test10); // new_test10.js 
    Xrm.Page.getAttribute("customertypecode").addOnChange(test2); // new_account_main.js 
    Xrm.Page.getAttribute("fax").addOnChange(fax_onChange); // new_account_main.js 

    onLoadUpdate(); // new_XrvSvcToolkit.Samples.updateRecord.js 
    //onLoadCreateDemo(); // new_XrvSvcToolkit.Samples.createRecord.js 
    onLoad(); // new_account_main.js 
    MultiSelect_ConvertToMultiSelect(); // new_MultiSelect.js 

SnapShot! generates a file called Events.js, found in the ForDevelopers sub-folder. Within Events.js you will find one form_Onload() function for each entity form that contains JavaScript. The events are laid out like this:

  • OnSave Events
  • OnChange Events
  • Calls to function specified as OnLoad events.

This form_OnLoad() method will be used to replace the existing onLoad() method and will allow you to maintain your JavaScript events using code instead of configuration.

Note: You can also see that even though an event was disabled, onLoadCreateDemo, the code was still generated, only “commented out” so that it is inactive. This allows you to reactivate it later should the method become relevant again.

Leave a Reply 0 comments