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:
getSaveMode: Returns a value indicating how the save event was initiated by the user.
isDefaultPrevented: Returns a value indicating whether the save event has been canceled because the preventDefault method was used in this event hander or a previous event handler.
preventDefault: Cancels the save operation, but all remaining handlers for the event will still be executed.
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:
function preventAutoSave(econtext) { var eventArgs = econtext.getEventArgs(); if (eventArgs.getSaveMode() == 70) { eventArgs.preventDefault(); } }
Cheers
[…] CRM 2013 – Client API: Save Event Arguments […]
[…] CRM 2013 – Client API: Save Event Arguments […]
[…] CRM 2013 – Client API: Save Event Arguments […]
[…] CRM 2013 – Client API: Save Event Arguments […]