USD – SessionCloseRequested

Within Unified Service Desk (USD) for Microsoft Dynamics CRM you may often encounter situations when you want to prevent a session being closed until a minimum set of data has been entered. In this post I will give an example of one way of achieving this.

If you are using sessions you will already have a hosted control of USD Component type “Session Tabs”. Mine is shown below.

On your session tabs hosted control you will find several events, one of which is “SessionCloseRequested”. (See below)

This event is triggered as soon as an operator tries to close a session but BEFORE the session actually closes. Meaning we can add actions to validate the session contents and then only close if the contents are valid. Below I have shown one possible example of how this might be achieved;

In my SessionCloseRequested I have shown three actions.

Notice the Order it is very significant!

  • The first sets a replacement parameter in the current context with a value of “Valid”.
  • The second displays a message if the details being closed are invalid AND changes the value in the context to say “Invalid”.
  • The third action will close the session IF (and only if) the value in the context is still set to Valid.

To explain the concept in greater detail let’s look at each action in turn ….

1 – CRM Global Manager – CopyToContext (SessionClose=Valid)

This action is very simple, the hosted control is “CRM Global Manager”, the action is “CopyToContext”. Then the data portion contains the “variable” I want to store in the current context. I’ve set a variable called “SessionClose” to Valid. SessionClose=Valid

What I am doing here is effectively defaulting as being valid. (Implying that by default the session will close.)

10 – CRM Global Manager – Display Message (Invalid Account)

There are actually two actions that come into play at this point! But let’s look at the message first.

The message is pretty simple. The hosted control is “CRM Global Manager”, then the action is “DisplayMessage”. This will simply trigger a popup containing the details in the data portion.

Now in my data portion I say text=<<an error message>> and caption =ERROR. This results in a popup that looks like this ….

My action looked like this ….

Importantly, I then added a condition to this action is onl;y display when the accounts website is blank.

The condition checks two things! Firstly the InitialEntity must be an “account”, as I only want this error to happen when I have loaded an account. And secondly it looks at the websiteurl.

Tip: You could obviously check other fields or even call a scriptlet to validate multiple fields if you need to get more complex.

“[[$Context.InitialEntity]]”==”account” && “[[account.websiteurl]+]”==””

Now for the second action I mentioned …. If the message is displayed a sub action will be triggered. You can see the sub actions from the navigation menu in the first action.

Below you can see that a sub action is being trigged that will update the value we have already set in the context.

The action detail is shown below. Notice that the hosted control is “CRM Global Manager” and the action is “CopyToContext”. And also that the data portion is “SessionClose=Inavlid”.

By triggering this sub action we will have signified that the session shouldn’t close.

100 SessionTab – Close Session (When SessionClose=Valid)

And then we have the final action, if the session is “valid” it will be closed otherwise it will remain open. The action is pretty simple, the hosted control is “Session Tabs” and the action is “CloseSession”.

I have also added a condition to confirm it is valid to close the session. “[[$Context.SessionClose]]”==”Valid”

Hopefully you’ll find this concept pretty easy to follow and can see how you could extend it to be more comprehensive in a real world situation. J

3 thoughts on “USD – SessionCloseRequested

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

  2. Pingback: USD – RefreshRequested | Microsoft Dynamics CRM and Unified Service Desk

  3. Pingback: USD – RefreshRequested - Microsoft Dynamics CRM Community

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 )

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