Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Save and refresh record entity after finishing dialog process

Posted on by 450

Hi All, I have created a dialog process, I call it when a button on the ribbon is clicked.
I wanna when dialog has finished its job( the dialog window closed and finished) the record entity save and reload.

Here is the code that run the dialog :

(function() {
Develop1_RibbonCommands_runDialogGrid = function(ids, objectTypeCode, dialogId) {
    if ((ids == null) || (!ids.length)) {
        alert(window.LOCID_ACTION_NOITEMSELECTED);
        return;
    }
    if (ids.length > 1) {
        alert(window.LOCID_GRID_TOO_MANY_RECORDS_IWF);
        return;
    }
    var rundialog = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
    rundialog.get_query()['DialogId'] = dialogId;
    rundialog.get_query()['ObjectId'] = ids[0];
    rundialog.get_query()['EntityName'] = objectTypeCode;
    openStdWin(rundialog,buildWinName(null),615,480,null);
}
Develop1_RibbonCommands_runDialogForm = function(objectTypeCode, dialogId) {
    var primaryEntityId = Xrm.Page.data.entity.getId();
    var rundialog = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
    rundialog.get_query()['DialogId'] = dialogId;
    rundialog.get_query()['ObjectId'] = primaryEntityId;
    rundialog.get_query()['EntityName'] = objectTypeCode;
    var hostWindow = window;
        if (typeof(openStdWin) == 'undefined') {
            hostWindow = window.parent; // Support for Turbo-forms in CRM2015 Update 1
        }
        if (typeof(hostWindow.openStdWin) != 'undefined') {
            hostWindow.openStdWin(rundialog, hostWindow.buildWinName(null), 615, 480, null);
            // window.location.reload(true);
        } 

}
})();

Depending on this source code, how can it be possible?

*This post is locked for comments

  • Suggested answer
    Vipin J Profile Picture
    Vipin J 1,583 on at
    RE: Save and refresh record entity after finishing dialog process

    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

  • Verified answer
    Flydancer Profile Picture
    Flydancer 1,332 on at
    RE: Save and refresh record entity after finishing dialog process

    Sadly there is no "onclose" event.

    Try something like this:

    var win = window.open(rundialog, 'windowname','width=615,height=480,status=0,toolbar=0');  
    
    var timer = setInterval(function() {  
    
       if(win.closed) {  
    
           clearInterval(timer);  
    
           alert('closed');  // window.location.reload(true)
    
       }  
    
    }, 1000);

    The code will check every second if your dialog has been closed and execute your code/reload if so.

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Save and refresh record entity after finishing dialog process

    Hi Albert,

    The below code is working fine for me:

    parent.window.location.reload(true);

  • Suggested answer
    Kevin Grech Profile Picture
    Kevin Grech 380 on at
    RE: Save and refresh record entity after finishing dialog process

    this is a small section of the code we use to close the case after the dialog is closed (whether it's finished or cancelled. no microsoft code used):

    //function

    function RefreshCaseForm(dlgWindow) {

       if (typeof (dlgWindow.window) == "unknown") {

           Xrm.Page.ui.close();

       }

       else {

           setTimeout(RefreshCaseForm, 1000, dlgWindow);

       }

    }

    //core code

    var win = window.open(url, null, "height=500, width=600, status=yes, toolbar=no, menubar=no, location=no", false);

    setTimeout(RefreshCaseForm, 1000, win);

  • Albert_ Profile Picture
    Albert_ 450 on at
    RE: Save and refresh record entity after finishing dialog process

    No luck sir !

    :-<

  • Albert_ Profile Picture
    Albert_ 450 on at
    RE: Save and refresh record entity after finishing dialog process

    When I put that there,It just refresh and reload as the dialog appears, not when dialog finish its job.

  • Albert_ Profile Picture
    Albert_ 450 on at
    RE: Save and refresh record entity after finishing dialog process

    MY CRM Version is 2011 .   :-)

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Save and refresh record entity after finishing dialog process

    Hi Albert,

    Check this thread -

    stackoverflow.com/.../dynamics-crm-2016-online-refresh-record-after-using-dialog

    ==============Extract from above link=======

    EDIT (based on your posted code): If the 5th parameter of the function openStdDlgWithCallback is the callback for when the dialog closes you'd want to pass the function like Xrm.Page.data.refresh or wrap your call in a function function(){Xrm.Page.data.refresh()}. Currently your code is executing the function right away which is why you're seeing the refresh right away.

    =================

    Hope this helps.

  • Inogic Profile Picture
    Inogic 24,094 on at
    RE: Save and refresh record entity after finishing dialog process

    Try with below code which is highlighted:

     

    (function() {

    Develop1_RibbonCommands_runDialogGrid = function(ids, objectTypeCode, dialogId) {

        if ((ids == null) || (!ids.length)) {

            alert(window.LOCID_ACTION_NOITEMSELECTED);

            return;

        }

        if (ids.length > 1) {

            alert(window.LOCID_GRID_TOO_MANY_RECORDS_IWF);

            return;

        }

        var rundialog = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');

        rundialog.get_query()['DialogId'] = dialogId;

        rundialog.get_query()['ObjectId'] = ids[0];

        rundialog.get_query()['EntityName'] = objectTypeCode;

        openStdWin(rundialog,buildWinName(null),615,480,null);

    }

    Develop1_RibbonCommands_runDialogForm = function(objectTypeCode, dialogId) {

        var primaryEntityId = Xrm.Page.data.entity.getId();

        var rundialog = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');

        rundialog.get_query()['DialogId'] = dialogId;

        rundialog.get_query()['ObjectId'] = primaryEntityId;

        rundialog.get_query()['EntityName'] = objectTypeCode;

        var hostWindow = window;

            if (typeof(openStdWin) == 'undefined') {

                hostWindow = window.parent; // Support for Turbo-forms in CRM2015 Update 1

            }

            if (typeof(hostWindow.openStdWin) != 'undefined') {

                hostWindow.openStdWin(rundialog, hostWindow.buildWinName(null), 615, 480, null);

                // window.location.reload(true);

            }

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

                      window.location.reload(true);

     

    }

    })();

     

    Thanks!

  • Kevin Grech Profile Picture
    Kevin Grech 380 on at
    RE: Save and refresh record entity after finishing dialog process

    I ran the dialog in a window and saved it in a variable. Then in the next line I set an interval that would check its type in the same calling function. Once the dialog was closed I triggered an Xrm.Page.data.refresh() and stopped.

    In your case, I'd put it after this line:

     openStdWin(rundialog,buildWinName(null),615,480,null);

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans