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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Javascript version 9.2 - GetSave Mode

(0) ShareShare
ReportReport
Posted on by 694

Good Morning,

Does anyone know what is the new javascript to prevent saving the form and to close the form for CRM that is above version 9.0?

Thank you

I have the same question (0)
  • Suggested answer
    - Matt Bayes - Profile Picture
    890 on at

    Hey Ricardo,

    The new Dynamics 365 Client API has a method to prevent the form from saving, as shown below:

    function PreventSave(executionContext)
    {
        var saveMode = executionContext.getEventArgs().getSaveMode();
        
        if (saveMode == 1 || saveMode == 2 || saveMode == 70) {
            //Save, Save and Close, or Auto Save
            
            //Prevent the save
            executionContext.getEventArgs().preventDefault();
        }
    }

    As for closing the form, I'm not sure what you mean. If you wanted to redirect away from the form to elsewhere in the system you could use:

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/navigateto

    Depending on whether or not you are using the Unified Interface, the above snippets/links may or may not be relevant.

    Thanks.

    Matt Bayes

  • Ricardo Rodrigues dos Santos Profile Picture
    694 on at

    Hi,

    Thank you for your help.

    The code is right is preventing the form from being saved, but now I need Javascript to close the form.

    Would you know what this code is?

    Tanks

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I believe formContext.ui.close() is what you're looking for - docs.microsoft.com/.../close

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans