USD – Prevent Close Window Dialog

I have been repeatedly asked a question about Unified Service Desk (USD) for Microsoft Dynamics CRM, how do we stop the often annoying “webpage you are viewing is trying to close the window” dialog?

In this post I will show you a couple of approaches I have used to solve this problem.

By way of an example I will use a phone call. You can see below that I have started a session containing an inbound phone call. Out of the box if the user clicks “Mark Complete” they will see the annoying dialog.

Below you can see that Internet Explorer has detected that the window is trying to close and this has created an unwanted prompt in Unified Service Desk. You may think seeing this isn’t much of a problem but think again. USD is aimed at contact centre operators, someone in that environment could easily take or make 300 phone calls per day. After clicking “Yes” a few hundred times you may find the operators will start to form a dislike of the developer who provided that feature. J

I have two possible approaches to solving this problem. This first is to simply allow the window to close but to prevent the popup.

The second is allow the phone call to be marked as complete but to leave the tab open. (I will explain this option and why you might want to do this in a second.)

  • Option One – Prevent Dialog
  • Option Two – Prevent Dialog (Keeping tab open)

Note: You can find an updated version of option one here.

Option One – Prevent the Dialog.

The steps for option one include ….

  1. Create a RunScript Action.
  2. Add the action to BrowserDocumentComplete Event.

Step One – Create a RunScript Action.

You can use a RunScript action to substitute the normal close window function with one that will close the tab “nicely” in USD. The function will need to look like this;

function closeWindow(focus) {"http://close/");

My action call for phone call looked like the one below;

Step Two – Add the action to BrowserDocumentComplete Event.

I then simply added this to the “BrowserDocumentComplete” event of my phone call hosted control. As shown below.

Now when you run USD clicking Mark Complete on the phone call will simply complete the phone call and close the tab. Without the annoying dialog.

Option Two – Prevent the Dialog (Keeping tab open).

I have demonstrated how to prevent the dialog, so we are done. Right? Yes and no ….. as sometimes you may need a slightly different approach.

If I start a session for a contact, then phone a phone call in a second tab allowing the user to close that tab is perfectly acceptable. But if I start the session with the phone call as the first tab if the user closes that tab they are left with a session open that contains nothing. And we have another annoyance for the user.

In this circumstance you will want the user to be able to click “MARK COMPLETE” but the tab remain open. Leaving the tab open is easy but the screen won’t have refreshed. Meaning the now completed (read-only) phone call will still appear to be editable. Here is how I solved that challenge ….. the steps involved are;

  1. Create a RunScript Action.
  2. Add RunScript to BrowserDocumentComplete Event.
  3. Create a Refresh Action.
  4. Create an ExecuteOnTimeout Action.
  5. Add ExecuteOnTimeout Action to Saved Event.

Step One – Create a RunScript Action.

Firstly I created a RunScript action as before. But this time the function actually did nothing. Meaning the close didn’t happen.

function closeWindow(focus) {

Step Two – Add RunScript to BrowserDocumentComplete Event.

And I added this action call to the BrowserDocumentComplete event on phone call as before.

Step Three – Create a Refresh Action.

Next I need to refresh the phone call tab after it is saved, so I created an action to refresh the phone call page if it had been completed. This is simple enough the hosted control was “Phonecall” and the action was “Refresh”. Notice I also added a condition to the action of “[[phonecall.statecode]]”==Completed
I did this as I only wanted the phone call tab to be refreshed if the phone call had actually been marked as completed.

Step Four – Create an ExecuteOnTimeout Action.

Next I needed to consider when / how to trigger this action. The problem is you can simply add it to the “Saved” event on phone call. But just doing that can trigger yet another different annoying dialog!

To avoid this dialog, we need to ensure the phone call save has completed before we refresh the page. To achieve that I created another action. The timeout action looked like the one below. My hosted control this time was my global manager and the action was “ExecuteOnTimeout”. In the data field I entered “milliseconds=500”, this was going to add a ½ second delay. Now I didn’t want this delay randomly for no reason so I also added the same condition as before. “[[phonecall.statecode]]”==Completed

Having saved my ExecuteOnTimeout action I added the refresh action as a sub action. You will find the sub action calls option in the navigation bar of your “ExecuteOnTimeout” action.

My sub actions eventually looked like this;

Step Five – Add ExecuteOnTimeout Action to Saved Event.

One final step remained to add the ExecuteOnTimeout action to the “Saved” event on phone call. Meaning after a phone call was saved as completed after a ½ second pause the phone call tab will be refreshed. The operator will then be looking at the completed read-only phone call as required. Simples!

I hope you can see this is actually quite a simple thing to achieve.

9 thoughts on “USD – Prevent Close Window Dialog

  1. Pingback: USD – The Book | Microsoft Dynamics CRM and Unified Service Desk

  2. Hi Sir,

    Good morning !

    we are into great trouble 😦 & I need your help like never before…..Please trying to help !

    1.) Microsoft Unified Service Desk (USD) applications is not responding to existing configuration.
    2.) Microsoft Unified Service Desk (USD) applications is not responding to changes made to existing configuration.
    3.) When we are making completely new configuration, same changes are not reflecting.
    4.) Also the configuration changes done before is reflecting on some user but not reflecting on most of the user.

    Detailed Explanation:

    1.) *When I say that “USD not responding to new configuration” it means when I am trying to add a new toolbar button then its not reflecting initially but after few hours (minimum after 4 hours ) its start reflecting, on few Agents Machine but not to the all agents Machine. There a users where its not reflecting ever after 4 hours.

    2.) Similarly, when i am making changes to existing configuration its taking few hours to respond to changes (minimum after 4 hours) then its start reflecting changes, on few Agents Machine but not to the all agents Machine.

    3) Resultant, Call center agent is not able to Login to the CTI page & hence entire call center operation is stuck.

    This is the CTI Page URL :

    Any idea, how we can we deal with this? Please help !

    Liked by 1 person

    • This sounds bad!
      I have not seen this behaviour before.

      I think I would have to raise a call with Microsoft.

      Maybe try uninstalling one of the clients and reinstalling. To see what configuration it gets when you reload.


      • Also, I assume you aren’t using the option to cache your configuration? If you are try disabling that.
        I did see an issue once when the client computers had been locked down so much that they had no ability to write to the program directories. But I doubt that is your issue as you say the changes came down eventually. You could test with a user that you know has local admin rights to rule out that type of issue.


  3. I have to create a Clientcacheversion for all the USD agents then the USD application starts working on production environment as required but on my UAT environment, same thing are working without Clientcacheversion & changes reflecting in a normal way. Now i have to update Client cache every time …i make any chances in USD configurations


    • That would be expected behaviour!

      If you configure that cache option then USD will load faster. (After the initial load)
      But you will need to remember to up the version number every time a change is made.

      I normally disable the option in my dev environments when I am making loads of changes. And enable only in production when I have a stable environment.

      If your install is new and open to loads of changes, you might want to disable!


  4. Hello Sir,

    Great morning. I have a slightly different requirement, that need to show a warning popup when user the clicks on close of USD application itself at the top right corner. Can this be achieved? Thanks in advance.


    • I am aware of this challenge and I have had this myself in previous projects.
      The bad news is that we have no event when USD tries to close. We do for SessionCloseRequested but hot USD itself.

      Sometime ago I logged as an idea on CRM ideas requesting this feature. But I know of no plans to add this into the product. (But I think it would be great!)


Leave a Reply

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

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

Facebook photo

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

Connecting to %s