Form Event Programming

Form Event Programming in Dynamics 365

Microsoft Dynamics CRM forms are the primary interface used to interact with customer data. The more you customize your forms, the more you will imagine valuable ways to interact with your data.

The primary method used for customizing the behavior of Microsoft Dynamics CRM forms is by using event programming. Form event programming allows the developer, using Javascript, to customize how CRM behaves when users open a form, change data, click through tabs, or save data.

Tip! Want to learn Dynamics 365 development skills?  Check out Developer Environment and Developer Extending events.

Some of the most common examples of using form event programming are:

  • Automatically default values of certain fields when the value of another field is set
  • Trigger a lookup of some data based on the entered value of some field
  • Create calculated values based on various field values on the form.
  • Validate data entry by correcting invalid data
  • Alert users to data issues
  • Make fields visible/invisible or enabled/disabled based on various situations

The primary benefits of using form event programming to customize Microsoft Dynamics CRM behavior:

form event planning Microsoft Dynamics CRM

Microsoft Dynamics CRM provides various events that can occur on forms to trigger custom logic like data validations and data manipulations. These events execute functions written in Javascript that are stored within libraries as a web resource in CRM database. Each event handler specifies a single function (code) within a Javascript library and you can specify parameters that can be passed to the function.

On Load Event

The OnLoad event occurs once when a CRM form has fully loaded. Each OnLoad event handler will execute depending on its order as specified in form properties. For example, if there are two event handlers registered for OnLoad event of a form, then script for event handler 1 will execute first then event handler 2. The OnLoad event can be used to perform data pre-population, form layout changes, or interactions with other page elements.

OnSave Event

The OnSave event occurs once when the user clicks on any one of the three save buttons (Save, Save & Close and Save & New) or when code forces the form to save. Similar to OnLoad, any number of event handlers can be registered for OnSave of Form. OnSave event can be used for data validation and data manipulation.

The Save operation can be canceled if data validation fails.

OnChange Event

The OnChange event occurs at the field level. OnChange event triggers whenever data in a form field changes or focus is lost. Data validation happens before and after the OnChange event. Similar to OnLoad, any number of event handlers can be registered for OnChange of a field.

All fields support the OnChange event. The OnChange event does not occur if the field is changed using script.

Tab TabStateChange Event

The TabStateChange event occurs when the DisplayState of the tab changes due to user interaction or forced by applied script. This event can be used for changing a URL for an IFrame at run time within a tab or can be used also for data manipulations.

OnReadyStateComplete Event

The OnReadyStateComplete event triggers when content of the IFRAME has loaded fully. This event can be used while referencing IFRAME controls within scripts.

Do More with Dynamics 365

Expand your knowledge of Dynamics 365 through PowerObjects’ educational blogs.  Looking to learn in a more formal setting?  Check out our in-person training courses.

Want to learn development skills?  Check out Developer Environment and Developer Extending events.