Thursday, 5 March 2015

22:24 - No comments

CRM 2013 – Client API: Save | MS CRM

Event Arguments

There are a few useful additions that have been added to the client API around the Save event. They are 3 methods that have been formally introduced:
The key method is the getSaveMode function. Think about the new auto-save feature on updated forms. The getSaveMode function allow the JavaScript method executing on the Save event to know why/how the record is being saved. That gives you the flexibility as a developer to add some additional logic to handle your scenario… Below is the list of values returned by the getSaveMode function based on the entity type.


Entity
Event Mode
Value
All
Save
1
All
Save and Close
2
All
Save and New
59
All
AutoSave
70
Activities
Save as Completed
58
All
Deactivate
5
All
Reactivate
6
User or Team owned entities
Assign
47
Email (E-mail)
Send
7
Lead
Qualify
16
Lead
Disqualify
15
This is fantastic as you can now write script to handle very specific scenario like an activity being resolved, a record being saved and closed, assigned and other cases. Below is a usage example in which we prevent the auto-save from happening as presented in the SDK documentation:
Example code:
function preventAutoSave(econtext) {
   var eventArgs = econtext.getEventArgs();
   if (eventArgs.getSaveMode() == 70) {
      eventArgs.preventDefault();
   }

}

0 comments:

Post a Comment