Tuesday, June 11, 2013

CRM 2011 - How Save event is Initiated using Javascript?

I have recently encountered a scenario where I wanted to track the save event initiated while qualifying a lead to make sure some validations has to be implemented.

Using JavaScript we can identify each of the save event mode from CRM 2011 application using the below method.

executionobj.getEventArgs().getSaveMode();

This method returns a number from which the save initiated entity and the save mode can be identified.

Below are the supported return values for CRM 2011.
  • Applicable to all the entities
    • 1 - Save
    • 2 - Save and Close
    • 59 - Save and new
    • 5 - Deactivate
    • 6 - Reactivate
  • Activities entity
    • 58 - Save as completed
  • User or Teams owned entities
    • 47 - Assign
  • Email
    • 7 - Send
  • Lead
    • 16 - Qualify
    • 15 - Disqualify
There are many unsupported return values which can also be used. But that has to be on our own risk to use them.

When this method is added to the form make sure to enable the check box "Pass execution context as first parameter". This will get us the executionobj mentioned above. Below is an example of the sample method.

function getSaveMode(executionobj)



{
 
    return executionobj.getEventArgs().getSaveMode();


  
} 

No comments:

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...