Friday, January 6, 2012

Canceling the Save operation in CRM 2011

Method 1:

Add an OnSave event to the form:

Note: The pass execution context as first parameter checkbox is very important to this process. Without it, it will not work.

Inside the Contact_main_library.js web resource, we’ll add the following function:
function Form_onsave(executionObj)
var shouldSave = true;

if (shouldSave)
alert("Unable to save because of some reason or the other.");

Inside the OnSave function, we need to have some type of test to see if we should allow the record to be saved.
For this demonstration, we simply check the value of a variable called shouldSave. If true, then we display an error message to the user then execute the preventDefault() method which will instruct CRM to cancel the save operation.

Method 2:
Add an OnSave event to the form:
//if event.Mode is one means Save, event .Mode is two means Save&Close.
if(event.Mode == 1 || event.Mode ==2)
event.returnValue = false;
return false;

Reference :-
Gangs036-MS-CRM-Blogspot: Canceling the Save operation in CRM 2011

No comments:

Post a Comment