Answered by:
formContext.getEventArgs().preventDefault() does not work on "Save and close" event

Question
-
Hi,
I have a result field in my appointment and phone call entity which users are supposed to enter the data only when they want to complete the activity. if they enter something in it and try to save(schedule) the activit, the save event must be canceled and a pop up message for the user must be displayed. this was working great with "event.returnValue=false" but now that we have upgraded to CRM 2013 this doesn't work and I have to use formContext.getEventArgs().preventDefault()
The issue is that this function cancels the save but tries to close the window after that which IE pops up another message saying that you have unsaved data and if you want to still be on the page press cancel. this is an extra step and not nice at all.Do you have any ideas?
here is a part of my code on form Save: ( I have also tried return false; after the function
function Form_onsave(formContext) { var SaveMode = formContext.getEventArgs().getSaveMode(); //alert(SaveMode); // 1 = Save 2= Save and Close 5=Deactivate 58= Save and Complete switch (SaveMode) { case 2: if (result != null) { alert("Open activities cannot have a result code."); Xrm.Page.getControl("new_phonecallresult").setFocus(); // Cancel the save operation. formContext.getEventArgs().preventDefault(); } break; }
- Edited by Edwin Abdalian Friday, January 17, 2014 6:38 PM
Friday, January 17, 2014 6:33 PM
Answers
-
Salim saved my life. I used
Xrm.Page.data.save().then(successCallback, errorCallback) to control the behaviour of my save.
- Marked as answer by Edwin Abdalian Saturday, January 25, 2014 1:16 AM
Saturday, January 25, 2014 1:16 AM
All replies
-
hi
Please try this below code
if u want to give any notification on error messge for the particular field-
OnFormSave_Account:
function
(econtext) {
var
eventArgs = econtext.getEventArgs();
if
(eventArgs.getSaveMode() == 70
//autosave
|| eventArgs.getSaveMode() == 1)
//manual save or Xrm save
{
if
(
this
.SetSICCodeFormNotification() ==
true
) {
//Prevent auto/manual save
eventArgs.preventDefault();
}
}
}
Saturday, January 18, 2014 12:11 PM -
unfortunately this doesn't help me. Like I described in my post, I'm able to cancel the save process but I cannot cancel the form close process. when I press "Save and Close" button, the preventDefault function cancels the save but the form closes after that and users cannot fix the validation issues.Saturday, January 18, 2014 8:56 PM
-
Salim saved my life. I used
Xrm.Page.data.save().then(successCallback, errorCallback) to control the behaviour of my save.
- Marked as answer by Edwin Abdalian Saturday, January 25, 2014 1:16 AM
Saturday, January 25, 2014 1:16 AM -
I tried this code also, but then it keeps stuck on the page, how did you use that for controling the behavior? how to let the callback stops?Friday, April 11, 2014 8:05 AM