Pages

Monday, 8 July 2013

CRM 2011: Client-side (forms, fields, tabs and IFrame) events in Microsoft Dynamics CRM 2011

1. Form Events

There are two events at the form level in Microsoft Dynamics CRM 2011
  • OnLoad Event
  • OnSave Event

OnLoad Event

The OnLoad event occurs after the form has been loaded. Normally OnLoad event is used to apply logic relevant to user interaction like
  • Display/Hide components on the form
  • Enable/Disable components on the form
  • Alert users of a specific business situation 
  • Perform calculations/actions using web service calls etc.

OnSave Event

OnSave event occurs after the form is saved. Normally following actions cause the form to be saved
  • User clicks the "Save" button
  • User clicks the "Save and Close" button
  • Other actions also cause the form to be saved, the Save method in the JavaScript
    • Xrm.Page.data.entity.save( null | "saveandclose" |"saveandnew" )
    • save() - if no parameter is included then it simply saves the record
    • save("saveandclose") - save and close the record form
    • save("saveandnew") - save current record and open new record form
OnSave event is commonly used for data validation or to perform a specific operation using web services.

The OnSave event can also be cancelled to prevent the data from being saved, following JavaScript code can be used to cancel the save operation.

event.returnValue = false;
return false;

2. Field Events

OnChange Event

OnChange event is available for every field on the form. The OnChange event triggers when the following two actions occur
  • The field data changes AND
  • The field loses focus
This event is commonly used to do the following
  • Display/Hide components on the form
  • Mark other fields mandatory or non-mandatory based on this field's value
  • Implement dynamics option sets
  • Perform calculations/actions using web service calls to change other fields based on changing values
  • formatting (e.g phone field)
OnChange event can also be triggered by invoking FireOnChange method for a specific field.

3. Tab Events

TabStateChange Event

TabStateChange event occurs when a tab is expanded or collapsed, implementing this event can defer the execution of code until a tab state is changed.


4. IFRAME Events

OnReadyStateComplete Event

OnReadyStateChange event is the indication that the contents of the IFRAME has been loaded and are available to be accessed in the script. If the script interacts with the IFRAME contents before they are fully loaded, the script will fail.


No comments:

Post a Comment