locked
How to stop closing form in Save & Close RRS feed

  • Question

  • When user clicks on Save & Close, I am trying to delay closing form using setTimeout in JavaScript, for some reason it is not delaying for the specified time period.It is getting closed immediately.

    calling this in onSave

    setTimeout(“My JavaScript function name”,5000)

    Is there any way stop closing or delaying form in Save & Close?

    Thanks.


    • Edited by Venkat_Reddy Thursday, January 31, 2013 10:08 PM
    Thursday, January 31, 2013 10:07 PM

Answers

  • Hi,

    The setTimeout will not pause execution and wait - but rather execute the function asynchronously after the give time. This means the save function continues and still saves.

    I'm interested as to why you need to delay the save? 

    If you really need to, you could create an on save function that cancels the first time, then schedules a second save:

    In the onsave function:

    1. if (window.hasSaved == true) return;

    2. window.hasSaved = true;

    3. setTimeOut(saveCallback,5000)

    4. Use preventDefault http://msdn.microsoft.com/en-us/library/gg509060.aspx#BKMK_preventDefault) to prevent the form from saving the first time around.

    In the saveCallback function, call Xrm.Page.data.entity.save();


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, January 31, 2013 11:09 PM
    Answerer

All replies

  • Hi,

    The setTimeout will not pause execution and wait - but rather execute the function asynchronously after the give time. This means the save function continues and still saves.

    I'm interested as to why you need to delay the save? 

    If you really need to, you could create an on save function that cancels the first time, then schedules a second save:

    In the onsave function:

    1. if (window.hasSaved == true) return;

    2. window.hasSaved = true;

    3. setTimeOut(saveCallback,5000)

    4. Use preventDefault http://msdn.microsoft.com/en-us/library/gg509060.aspx#BKMK_preventDefault) to prevent the form from saving the first time around.

    In the saveCallback function, call Xrm.Page.data.entity.save();


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, January 31, 2013 11:09 PM
    Answerer
  • Thanks for your answer. got it. doing something like that. Here is my code. Aborting System Save&Close, manually saving and then it gets OnLoad. in OnLoad i can delay.

    function Form_OnSave()
     {
     //If it is Save & Close
     if(event.Mode == 2)
     {
     AbortSave();
     Xrm.Page.data.entity.save();
     }
     
    function AbortSave() {
         event.returnValue = false;
         return false;
     }

    function Form_OnLoad()
    {
    setTimeout(RefreshAccountContacts,10000);
    }

    Friday, February 1, 2013 10:04 PM
  • Well done - thanks for letting us know and for posting your code.

    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, February 1, 2013 11:00 PM
    Answerer