Answered by:
CRM 2011: Cancel save function using javascript

Question
-
I have a requirement in case entity where I need the user to able only update the case using the resolve option and not the save buttons, i.e if the status reason equals closed and the satisfaction level is set the user MUST resolve the case and not only saving it
Anyway to do it ??
Thanks and best regards..
- Edited by Mostafa Moatassem Thursday, March 8, 2012 4:17 PM
Thursday, March 8, 2012 4:15 PM
Answers
-
So you are looking at something like this...
function OnSave(executionObj) { var saveMode = executionObj.getEventArgs().getSaveMode(); if (saveMode != 5) { //Resolve Case button not selected //Do your criteria check if (Xrm.Page.getAttribute("statuscode").getSelectedOption().text == "Closed" && Xrm.Page.getAttribute("customersatisfactioncode").getSelectedOption() != null) { //If it fails, alert the user and prevent the save alert("Use The Resolve Case Button"); executionObj.getEventArgs().preventDefault(); } } }
Here is a bit more information on the execution context.Jason Lattimer
- Proposed as answer by JLattimerMVP, Moderator Friday, March 9, 2012 4:43 AM
- Marked as answer by Mostafa Moatassem Friday, March 9, 2012 10:32 PM
Friday, March 9, 2012 4:43 AMModerator
All replies
-
function OnSave(executionObj) { //do you check - and if not allowed to save executionObj.getEventArgs().preventDefault(); }
Make sure you have "Pass execution context as first parameter" checked when you reference your function in the OnSave event.Jason Lattimer
- Proposed as answer by JLattimerMVP, Moderator Thursday, March 8, 2012 4:35 PM
Thursday, March 8, 2012 4:35 PMModerator -
Thanks alot for your help, would you please provide more explanation ?
function OnSave(executionObj) { //do you check - and if not allowed to save ----- //just a reminder that I need to be allowed to save in case of pressing the Resolve button executionObj.getEventArgs().preventDefault(); }
Also I need that you explain the execution parameter
Thanks and best regards..
Thursday, March 8, 2012 10:40 PM -
I think following code is work.
event.returnValue = false;
return false;
Friday, March 9, 2012 4:27 AM -
So you are looking at something like this...
function OnSave(executionObj) { var saveMode = executionObj.getEventArgs().getSaveMode(); if (saveMode != 5) { //Resolve Case button not selected //Do your criteria check if (Xrm.Page.getAttribute("statuscode").getSelectedOption().text == "Closed" && Xrm.Page.getAttribute("customersatisfactioncode").getSelectedOption() != null) { //If it fails, alert the user and prevent the save alert("Use The Resolve Case Button"); executionObj.getEventArgs().preventDefault(); } } }
Here is a bit more information on the execution context.Jason Lattimer
- Proposed as answer by JLattimerMVP, Moderator Friday, March 9, 2012 4:43 AM
- Marked as answer by Mostafa Moatassem Friday, March 9, 2012 10:32 PM
Friday, March 9, 2012 4:43 AMModerator -
function opponsave(executionObj)
{
var lookupItem=new Array();
lookupItem=Xrm.Page.getAttribute("new_directionid").getValue();
var lookupcallsubstatus=new Array();
lookupcallsubstatus=Xrm.Page.getAttribute("new_callsubstatus").getValue();
if(lookupItem==null)
{
alert('!');
executionObj.getEventArgs().preventDefault();
}
else if(Xrm.Page.getAttribute("new_phoneduration").getValue() ==null)
{
alert('!');
executionObj.getEventArgs().preventDefault();
}
else
{
executionObj.getEventArgs().getSaveMode();
}
}and you should choose pass execution context as parameter
Software Specialist Crm
- Proposed as answer by Ahmet Çankaya Saturday, March 10, 2012 9:04 PM
Friday, March 9, 2012 7:47 AM