Friday, June 26, 2009

Closing CRM Case window upon resolve

This will be my first blog post on MSCRM tricks I've learned throughout my experience. It arose from the simple usability question from a customer of mine: "Why do I have to close the case windows myself after resolving it?".
It filled my mind for a few days, because he had a point. The case form is after all read-only once resolved. And fortunately I came up with a simple and easily implementable solution with a simple onload JavaScript:
if (window.opener) {
  var resolveMenuItem = document.getElementById('_MIresolve');
  if (resolveMenuItem) {
    resolveMenuItem.action = 'window.opener.openCaseWindow = window; resolve();';
  }

  try {
    window.opener.openCaseWindow.close();
    window.opener = null;
  }
  catch(e) {}
}


The above JavaScript located the Resolve menu item (from the Actions menu) and changes the action on that if it exists. The action is prepended with a simple line that stores a reference to the current case window on the opening form, i.e. the main MSCRM window, an account form or what ever window the case was opened from. Finally it tries to close the window to which a reference has been stored.


Hence, when you click the resolve case menu item, a window reference will be save. When the standard MSCRM resolve dialog is filled in and ok is pressed, the case form will be submitted to persist the resolve data and once the form load again it will trigger the action to close itself.


Note that this will note work if a case is opened from a link in e.g. an email.

No comments:

Post a Comment

AddThis