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)

How to refresh a form at the end of a dialog

(0) ShareShare
ReportReport
Posted on by 140

Dear all,

I have investigated many hours to find a solution for my problem but i did not find something right. I change some fields in my underlie form by dialog. If the dialog will close the user did not see the important changes (e.g. a filled lookup field).

Is there a possibility to reload a form when a dialog is finished?

Some important hint: The dialog starts by an OnLoad Script if the record is in a certain status with the following code:

window.open("/" + Xrm.Page.context.getOrgUniqueName() + "/cs/dialog/rundialog.aspx?DialogId=%7b24C3F6F7-0ED8-4093-9AB8-F45AC38075D5%7d&EntityName=salesorder&ObjectId=" + Xrm.Page.data.entity.getId());

Maybe I can wait on a close-event by this dialog or something else?

Thanks a lot.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    jlattimer Profile Picture
    24,562 on at
    RE: How to refresh a form at the end of a dialog

    You could try something like this:

    function OpenDialog() {
        OpenDialogWithRefresh("95c0e04c-b3cd-4684-9877-38f01c03f198", "account", Xrm.Page.data.entity.getId());
    }
    
    function OpenDialogWithRefresh(dialogID,entityType, recordId) {
        window.showModalDialog(Xrm.Page.context.getClientUrl() + "/cs/dialog/rundialog.aspx" + "?DialogId=" + dialogID + "&EntityName=" + entityType + "&ObjectId=" + recordId, null, "dialogHeight:600px;dialogWidth:800px;center:yes; resizable:1;maximize:1;minimize:1;status:no;scroll:no");
        window.location.reload(true);
    }
    
  • MDoddio73 Profile Picture
    1,910 on at
    RE: How to refresh a form at the end of a dialog

    We often launch Dialogs from Ribbon buttons to save a few clicks. But you could fire this code in the OnLoad event too, specifying if you wish to refresh, by setting the function param to "true".

    If you were to use this function with a Ribbon button, the action would be a JavaScript Function, and the params would be (in order) String, String, Crm Parameter, Boolean Parameter.

    var popup;

    var detailsWindowTimer;

    function LaunchModalDialog(dialogID, typeName, recordId, refresh) {

       var url = window.location.protocol + "//" + window.location.host;

       if (window.location.href.indexOf(Xrm.Page.context.getOrgUniqueName()) > 0) {

           url = url + "/" + Xrm.Page.context.getOrgUniqueName();

       }

       url = url + '/cs/dialog/rundialog.aspx';

       popup = window.open(url + '?DialogId=' + dialogID + '&EntityName=' + typeName + '&ObjectId=' + recordId, "Dialog", "status=0,toolbar=0,scrollbars=0, resizable=1");

       if (refresh != null && refresh == true) {

           detailsWindowTimer = setInterval("WatchDetailsWindowForClose()", 600); //Poll

       }

    }

    function WatchDetailsWindowForClose() {

       if (!popup || popup.closed) {

           /// Do your stuff here....

           clearInterval(detailsWindowTimer); //stop the timer

           window.location.reload(true);

       }

    }

  • Simon Eschen Profile Picture
    140 on at
    RE: How to refresh a form at the end of a dialog

    Thank you very much for your help.

    So my problem instead is solved, because your solutions works. But in this case another problem occurs.

    I get the message if I want really leave this site caused by my implemented reload.

    Is there any opportunity to suppress this message for this case?

  • MDoddio73 Profile Picture
    1,910 on at
    RE: How to refresh a form at the end of a dialog

    This is probably because the data on the form has been modified prior to executing the CRM Dialog.

    You could try modifying the WatchDetailsWindowForClose function:

    function WatchDetailsWindowForClose() {

      if (!popup || popup.closed) {

          /// Do your stuff here....

          clearInterval(detailsWindowTimer); //stop the timer

          if(Xrm.Page.data.entity.getIsDirty() == true) {

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

          } else {

               window.location.reload(true);

          }

      }

    }

  • triangular Profile Picture
    162 on at
    RE: How to refresh a form at the end of a dialog

    Hi Michael,

    Sorry for resurrecting an old thread.

    Thanks for posting your code. Initially I only had three parameters for dialogID, typeName and recordID (string, string and GUID), and then just added a new boolean one for refresh.

    Then I modified my code slightly to contain your solution to refresh the page after the popup window closed. However the page is never refreshed. I put some alert messages in my code however they never show up either.

    Any suggestion is appreciated, thanks.

    -tri

    function startDialog(dialogID, typeName, recordId, refresh)
    {
    var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
    var popup = window.open(serverUri + '?DialogId=' + dialogID + '&EntityName=' + typeName + '&ObjectId=' + recordId, "Dialog", "dialogHeight:600px;dialogWidth:800px;center:yes;resizable:1;maximize:1;minimize:1;status:no;scroll:no");


    var dialogWindow = openStdWin(serverUri + '?DialogId=' + dialogID + '&EntityName=' + typeName + '&ObjectId=' + recordId, "Dialog", "dialogHeight:600px;dialogWidth:800px;center:yes;resizable:1;maximize:1;minimize:1;status:no;scroll:no");

    //var timer = setInterval(function () { attachActionAfterClose(dialogWindow) }, 1000);

    alert("bah");

    //if (refresh != null && refresh == true) {
    var detailsWindowTimer = setInterval("WatchDetailsWindowForClose()", 600); //Poll

    }

    function WatchDetailsWindowForClose() {
    if (!popup || popup.closed) {
    alert("refreshing!!");
    clearInterval(detailsWindowTimer); //stop the timer
    window.location.reload(true);
    }

  • Suggested answer
    VPrashant Profile Picture
    675 on at
    RE: How to refresh a form at the end of a dialog

    Hi Triangular,

    Try this:

    Xrm.Page.data.refresh(true);

    instead of window.location.reload(true);

    It worked from me.

    A big Thank you to Michael Dodd. You code helped me make my day.

    I was not able to mark your post as THE answer. How should I do it? :) 

  • chauhanhardik Profile Picture
    687 on at
    RE: How to refresh a form at the end of a dialog

    Hi triangular,

    Have you got your page refreshed after the popup closed?

    If yes, can you please help me to do so?

    Thanks,

    Herry

  • chauhanhardik Profile Picture
    687 on at
    RE: How to refresh a form at the end of a dialog

    If you are able to refresh a form at the end of dialog, then can you please help me to do so?

    Any suggestion is appreciated, Thanks,

    Herry

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at
    RE: How to refresh a form at the end of a dialog

    There is not out of box feature to support this, but I created a generic method to refresh the form after dialog process completes with some button custom JScript.

    Here is a complete blog post for detailed answer

    http://vjcity.blogspot.com/2019/01/refresh-form-after-dialog-process.html

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