Tuesday, 21 November 2017

Call any method after OnSave in MS CRM

There are many scenarios which requires a custom action to be performed after saving a record. For example: 
  • Set its status
  • Add a relationship, 
  • Update a field, 
  • Update another record
  • Call a model dialog etc

Microosft SDK has given this feature using which we can easily add or remove any method after save.
methods are:
  • Xrm.Page.data.entity.addOnSave
  • Xrm.Page.data.entity.removeOnSave
Syntax Code:

function addActionToOnSave() {
 Xrm.Page.data.entity.addOnSave(setRecordStatusInactive);
}
 
function removeActionFromOnSave() {
 Xrm.Page.data.entity.removeOnSave(setRecordStatusInactive);
}
 
function setRecordStatusInactive() {
 //code to set record status inactive
}


Hope this will help you.