3
votes

I have created a custom "Resolve Case" window that replaces the CRM's default case resolving window. What I have done is I've replaced the Resolve Case ribbon button with my own button which opens a custom HTML page when clicked. Then when the user press Resolve button on that page a SOAP message is created to resolve that particular case. After the SOAP message I call window.close() to close the "Resolve Case" window. After that I'm calling location.reload() so that the main form is reloaded and ribbon is refreshed. So it works (in user's point of view) just like the default case resolving window.

Now here's a problem. If the user, after resolving a case, reactivates it and then resolves it again I'm getting the following message (popup alert from browser):

"To display the webpage again, the browser needs to resend the information you've previously submitted. If you were making a purchase, you should click Cancel to avoid a duplicate transaction. Otherwise, click Retry to display the webpage again."

I discovered the problem is because I have used location.reload() to reload the main form and thus there occurs a duplicate form submission. I've tried to use window.location = window.location, location.href = location.href, etc. instead of location.reload() but none of them are working for me. They seemed to refresh the main form (at least it blinked), but the ribbon didn't refreshed. I also tried to use Xrm.Page.ui.refreshRibbon(), but it didn't make a difference either.

I searched a solution from internet and people are talking about Post/Redirect/Get pattern. I couldn't find any clear examples how to implement it though so I was hoping if you could help me to understand it and how to use it in this particular case.

More information and code samples will be provided if needed.

1
Do either of the solutions offered here help? [How to Refresh the parent Form in CRM Dynamics 5.0 after action is completed on custom child form?][1] [1]: stackoverflow.com/questions/4094058/…Jason Koopmans
Can you supply some example code including the window.location example too?Ollie

1 Answers

0
votes

I tend to use the following to refresh a record's form (you might want to wrap it in a function):

// Open form with same record.
var newWindow = Xrm.Utility.openEntityForm(entityName, entityId);

// After rollup 12, this function returns a boolean instead of
// the window object.
if (typeof newWindow === 'boolean') {
    // The name of the window, when the record is not new, is equal to the record GUID,
    // without {, } or - characters. When it is equal, were done. Otherwise, close
    // the current window.
    if (window.top.name.toLowerCase() === entityId.replace(/[\{\}\-]/gi, "").toLowerCase()) {
        return;
    }

    Xrm.Page.ui.close();
    return;
}

// Before rollup 12, the function returns a window object. Compare the window objects.
// When they're not equal, close the current window.
if (newWindow.top !== window.top) {
    Xrm.Page.ui.close();
    return;
}

In my experience, this consistently works.