Answered by:
CRM 2013 - OnSave code not cancelling the save

Question
-
I have a function which runs OnSave of a form, if certain criteria are met it will cancel the Save by using this command, this command does run and the alert returns 'true' but the record still saves.
This is only set to run when the getSaveMode is 5, so when I hit Deactivate it runs the code, alerts me as per below but still deactivates the record. How do you stop it deactivating the record? the code below doesn't seem to work.
Thanks
prmContext.getEventArgs().preventDefault(); alert("default prevented = " + prmContext.getEventArgs().isDefaultPrevented());
Pete
- Edited by Pete.CRM Tuesday, January 21, 2014 12:39 PM
Tuesday, January 21, 2014 12:26 PM
Answers
-
Hi Pete - seems like this might be a bug.
I tried the follow code on a form save (passing the execution object) and every time the record still deactivated. This did work in CRM 2011.
function OnSave(execObj) {
alert(execObj.getEventArgs().getSaveMode());
if (execObj.getEventArgs().getSaveMode() === "5" || execObj.getEventArgs().getSaveMode() === 5) {
execObj.getEventArgs().preventDefault();
}
}
I submitted to Connect here: https://connect.microsoft.com/dynamicssuggestions/feedback/details/816471/mvp-bug-cannot-cancel-form-save-deactivate-with-javascript
Jason Lattimer
My Blog - Follow me on Twitter - LinkedIn- Proposed as answer by JLattimerMVP, Moderator Monday, February 3, 2014 2:52 PM
- Marked as answer by Pete.CRM Monday, February 3, 2014 2:54 PM
Monday, February 3, 2014 2:52 PMModerator
All replies
-
Hi Pete,
just a suggestion, if you plan to control when a record can be activated/deactivated, I suggest to use a plugin, is a better solution.My blog: www.crmanswers.net - Rockstar 365 Profile
Tuesday, January 21, 2014 12:30 PM -
Hi Guido,
But this should be possible in jscript according to the sdk. I don't have any other functions onSave so any ideas why it doesn't work?
Thanks
Pete
Tuesday, January 21, 2014 12:32 PM -
use:-
prmContext.getEventArgs().preventDefault();
The pass execution context as first parameter checkbox is very important to this process. Without it, it will not work.Check the following site blogs.infinite-x.net/.../crm-2011-canceling-the-save-operation
Regards Faisal
- Edited by Faisal Fiaz Tuesday, January 21, 2014 1:29 PM
Tuesday, January 21, 2014 1:27 PM -
Faisal, that's exactly what I am using, see my original post.
Pete
Tuesday, January 21, 2014 1:29 PM -
Anyone? Really need this working
Pete
Monday, February 3, 2014 9:34 AM -
Hi
Could it be CRM 2013 feature thats deactivating the record. Try to disable it.
Check this link too : http://msdynamicscrmblog.wordpress.com/2013/10/17/disable-auto-save-functionality-in-dynamics-crm-2013/
Monday, February 3, 2014 1:32 PM -
that's already been turned off globally.
any other ideas?
Pete
Monday, February 3, 2014 1:34 PM -
Hi Pete - seems like this might be a bug.
I tried the follow code on a form save (passing the execution object) and every time the record still deactivated. This did work in CRM 2011.
function OnSave(execObj) {
alert(execObj.getEventArgs().getSaveMode());
if (execObj.getEventArgs().getSaveMode() === "5" || execObj.getEventArgs().getSaveMode() === 5) {
execObj.getEventArgs().preventDefault();
}
}
I submitted to Connect here: https://connect.microsoft.com/dynamicssuggestions/feedback/details/816471/mvp-bug-cannot-cancel-form-save-deactivate-with-javascript
Jason Lattimer
My Blog - Follow me on Twitter - LinkedIn- Proposed as answer by JLattimerMVP, Moderator Monday, February 3, 2014 2:52 PM
- Marked as answer by Pete.CRM Monday, February 3, 2014 2:54 PM
Monday, February 3, 2014 2:52 PMModerator -
Thanks Jason, it's not me going mad then :)
Pete
Monday, February 3, 2014 2:54 PM