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)

Prevent to run saveAndClose event in Crm 2016 with js

(1) ShareShare
ReportReport
Posted on by

Hi everyone,

I want to apply a validation on save and close button, if it returns false, want to prevent to close the form. How can I achieve? Any idea?

Thanks in advance,

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Prevent to run saveAndClose event in Crm 2016 with js

    Hi,

    Try with this  , attach the function in the onsave event ,dont forget to pass execution context .

        function preventSaveAndClose(econtext) {
    
            //Do your validation here 
    
            var isValid =false; // Set the false here if validation failed 
            var eventArgs = econtext.getEventArgs();
            if ((isValid == false ) && (eventArgs.getSaveMode() == 70)) {  
                eventArgs.preventDefault();
            }
        }

    You can find more details here  -

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg509060(v=crm.8)

  • Community Member Profile Picture
    on at
    RE: Prevent to run saveAndClose event in Crm 2016 with js

    Hi,

    I have tried this one but it does'nt prevent to close the from it's only prevent to save the form.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Prevent to run saveAndClose event in Crm 2016 with js

    Sorry I have not tried , check with this adding return false statement  -

    function preventSaveAndClose(econtext) {

    //Do your validation here
    var isValid =false; // Set the false here if validation failed
    var eventArgs = econtext.getEventArgs();
    if ((isValid == false ) && (eventArgs.getSaveMode() == 70)) {
    eventArgs.preventDefault();
    return false;
    }
    }

  • Flydancer Profile Picture
    1,332 on at
    RE: Prevent to run saveAndClose event in Crm 2016 with js

    Pass the context/executionobject to your onSave function and prevent saving with 

    executionObj.getEventArgs().preventDefault();

    Edit: sorry, didn't refresh the tab before answering

  • Community Member Profile Picture
    on at
    RE: Prevent to run saveAndClose event in Crm 2016 with js

    unfortunately, it doesnt work :(

  • Shooter McGavin Profile Picture
    on at
    RE: Prevent to run saveAndClose event in Crm 2016 with js

    After much research, the only solution I've found is to edit the ribbon to override the behavior of the Save and Close command itself.

    See the post from Dan Overton here: https://community.dynamics.com/crm/f/117/t/155316

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
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans