‘Save and close’ button issue

save

We were facing issue in ‘Save and Close’ button for an entity form. What happens, on first click of ‘Save and Close’ button, it just refresh the page, neither getting saved nor even getting closed.

Thus, after big research, we come to know its happening only if we are using two buttons on command bar then only this persist.

on exploration on that JavaScript,  we come to know that its happening because of page refresh code, we were refreshing CRM page by following lines..

  1. Xrm.Utility.openEntityForm(“quote”, quoteid);
  2. Xrm.page.data.refresh();
  3. window.location.reload();
  4. window.location.href = window.location.href;

 

So, after a little observation, we learned that only ‘Xrm.page.data.refresh();‘ is giving expected results, means ‘Save and Close’ button was saving the page and closing successfully as well.

But, story does nor finished here, above change was working only for one button not the other one.

Second button has a popup, and making some changes in entity and closes, but before it getting closed, it was refreshing entity form by ‘Xrm.Utility.openEntityForm(“quote”, quoteid);‘, and when we tried with ‘window.parent’ or ‘Xrm.page.data.refresh();‘, it was not able to refresh the page.

Here we were used following code to open popup

var lookupWin = window.open(sURL, “_blank”, sProperties);
lookupWin.focus();

we changed that with following changes …

New function,

function openDialog(uri, name, options, closeCallback) {
 var win = window.open(uri, name, options);
 var interval = window.setInterval(function () {
 try {
 if (win == null || win.closed) {
 window.clearInterval(interval);
 closeCallback(win);
 }
 }
 catch (e) {
 }
 }, 1000);
 return win;
};

and called that function by

var lookupWin = openDialog(sURL, "_blank", sProperties, function () { window.location.reload(); });
lookupWin.focus();

This resolve our ‘Save and close’ button issue.

Thanks.

for more explanation about the function is here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s