web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Cancel Save & Close event

(0) ShareShare
ReportReport
Posted on by

Hi,

how can I cancel a Save & Close event, when someone clicks the Save & Close button on an entity form?

I want to deny the closing action of the form, if a custom validation is invalid.

Thanks to all.

Regards

Marco

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Cancel Save & Close event

    Hi,

    You can write JavaScript Code on save of entity form. Perform custom validation in this code. Add condition in code that if custom validation is invalid then do not save entity form.

    Please find the following useful links to prevent saving entity form in MS Dynamics CRM-

    -crmbusiness.wordpress.com/.../crm-2011-quick-tip-javascript-to-stop-a-form-saving

    -community.dynamics.com/.../microsoft-dynamics-crm-2013-prevent-a-record-from-being-saved.aspx

    [If you find any helpful answer(s) of your question, please mark the answer(s) as verified answer(s).]

  • Mithilesh Kumar Profile Picture
    10,047 on at
    RE: Cancel Save & Close event

    Hi ClassMP,

    If you want to stop save you will need to use the preventDefault method.

    example

    function preventAutoSave(econtext) {
        var eventArgs = econtext.getEventArgs();
        if (eventArgs.getSaveMode() == 70 || eventArgs.getSaveMode() == 2) {
            eventArgs.preventDefault();
        }
    }


    Execution Context is passed as the first parameter.

    For more information on client side scripting, follow this article on MSDN

    https://msdn.microsoft.com/en-us/library/gg509060.aspx

    Hope that helps

    Thanks

  • Community Member Profile Picture
    on at
    RE: Cancel Save & Close event

    Thanks for your answer!

  • Community Member Profile Picture
    on at
    RE: Cancel Save & Close event

    this is not working in 2015 7.1 CRM that it is returning 70 for both auto save and navigating from page also it is 70 but when we turn on legacy it is giving 2 when navigating from page any answer or solution for this scenario....  

  • Community Member Profile Picture
    on at
    RE: Cancel Save & Close event

    Hi,

    after doing some tests it isn't working in CRM 2013 SP1 too.

    I tried it with following code:

    function myMethod(e) {

    var isValid = VerifyOnSave();

    if (!isValid) {

    //Show error message

    // alert(ErrorMessage);

    //Xrm.Utility.alertDialog(ErrorMessage);

    //Cancel current event

    if (e != null) {

    //e.getEventArgs().preventDefault();

    var eventArgs = e.getEventArgs();

    if (eventArgs != null) {

    eventArgs.preventDefault();

    }

    e.returnValue = false;

    /*window.onbeforeunload = function (){

    return ErrorMessage;

    }

    */

    }

    Xrm.Utility.alertDialog(ErrorMessage);

    }

    }

  • Nick Plourde Profile Picture
    on at
    RE: Cancel Save & Close event

    I have CRM 2013 SP1 too. When I try the preventDefault, then save is prevented but not the close. So, a save is triggered because I exit the form and a window appear. This is really bad.

  • Community Member Profile Picture
    on at
    RE: Cancel Save & Close event

    you need to save the record but doesn't want to close the form then just write a script in save method to

    function(e)

    if(e.eventargs !="save")

    Xrm.Page.data.save().then({

    e.stoppropogration();

    });

  • Jason M. Cosman Profile Picture
    5,234 Moderator on at
    RE: Cancel Save & Close event

    Hello Marco;

    Why not just hide the Save and Close button so they can't use it? They would have to save using the regular button.

  • Community Member Profile Picture
    on at
    RE: Cancel Save & Close event

    :) @ Jason M. Cosman

  • Community Member Profile Picture
    on at
    RE: Cancel Save & Close event

    Not wprking. I want to retain at same page and prevent the form to close when user click "Save & Close" button

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans