Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

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

$
0
0

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;
}




Viewing all articles
Browse latest Browse all 8223

Trending Articles