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 :
Microsoft Dynamics CRM (Archived)

How to make Save&Close event wait for few seconds and force execute save & Close

(0) ShareShare
ReportReport
Posted on by 70

Hi,

I am trying to prevent CRM 2011 default CRM form events of Save & Close and Save & New.

On Save & Close, I need to make form wait for 3 seconds and force close the form after 3 seconds.For this purpose, i used SeTimeout function to execute Xrm.Form.Ui.Close() function after 3 seconds 

But with this method, the problem i am having is Xrm.Form.Ui.Close() function behaves as windlow.close which ask for a pop up every time on save & close whether to save or discard my changes.

So, I used the below code:

if (context.getEventArgs().getSaveMode() == 2) {
context.getEventArgs().preventDefault();
setTimeout(function () {
Xrm.Page.data.entity.save('saveandclose');
}, 3000);
}

But it is not closing my form. Can you please suggest any alternative for this problem.

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    try below code to pause save and close for sometime.It seems to be working as i can alert before it closes.

    function preventAutoSave(econtext) {
    var eventArgs = econtext.getEventArgs();
    if (eventArgs.getSaveMode() == 2) {
    setInterval(function(){alert("Hello")},3000);
    }
    }

  • Anonymus Profile Picture
    70 on at

    I can pause the event successfully. But after pausing, I want to close the form. The close is not working.

    If I use, window.close() or Xrm.Form.Ui.Close() functions to close the form, there is an other popup coming everytime asking whether to save my changes or discard my changes.

  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    it showing the popup because still form is not yet saved. On save is called before crm saves the value. After pausing call save and close method as below

    Xrm.Page.data.entity.save("saveandclose")

  • Anonymus Profile Picture
    70 on at

    Hi Chitra,

    I have something like this:

    Xrm.page.data.entity.addOnSave(function(context){

    callsomefunction();

    //I need at least two seconds for this function to finish.

    if (context.getEventArgs().getSaveMode() == 2) {            

               context.getEventArgs().preventDefault();          

               setTimeout(function () {

                 Xrm.Page.data.entity.save("saveandclose");            

               }, 2000);          

           }

    }

    );

    This is making infinite loop. I need to find a way to close form after 2 seconds.

  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    Keep one global variable with value true or false. In the time out function set this variable value to true. Before calling the setimeout function check the value of this field and call settimeout function only when variable is false. This way you can avoid infinite loop.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans