locked
Javascript is executing two times on click of Save and Close button, MS CRM 2013 Online RRS feed

  • Question

  • Hi,

    Below is the code which i am using on Form OnSave event.

    function confirmClose(execObj) {
        Xrm.Utility.confirmDialog("Do you want to set the value?",
                function () {
                    //Set Value
                },
                function () {
                    execObj.getEventArgs().preventDefault();
                }
            );
    }

    It works fine on click of Save button (even if there are unsaved changes).

    But if there are unsaved changes and when i click on Save and Close button, 

     - Pop-Up opens "Do you want to set the value?".

     - Press "Cancel". - The message pop's up again saying "Do you want to set the value?".

    The code is getting executed again when i click on Cancel button. Could anyone suggest me what could be the issue. ?


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, May 22, 2014 11:33 AM

All replies

  • In CRM 2013 a Save is automatically executed every time you close a form.  Save is also executed automatically every 30 seconds (so your popup might execute again there, right?) if there are changes.  You will probably want to put a check in your JavaScript to only execute if the form has additional changes.  i.e.:

    if (Xrm.Page.data.entity.getIsDirty()) {

    //execute code here

    }

    Thursday, May 22, 2014 6:04 PM
  • Hi JBlaeske,

    Thanks for the reply.

    How can this check will help me?

    i meant, how can i make use of this check to avoid the second pop up ?

    However, i wanted to restrict saving the form and stay back in the same form, if a user clicks on Cancel button. 


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, May 23, 2014 7:09 AM
  • Hi All,

    Any help on this ?


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Tuesday, May 27, 2014 12:04 PM
  • The IsDirty flag should be reset after each successful save, so that if it tries to save the second time the above code should prevent your code from executing.
    Tuesday, May 27, 2014 12:13 PM