Sessions history – Capture Active & Total time of Session in USD

One of the most common business scenario while implementing USD in contact centers is to know the Total time the agent spent in a session and the time actively he/she worked on the session. This can be very good information for all those managers out there to understand the pattern of calls, time taking to deal with customers, ‘extra’ work of agent post session etc.

Though one of my previous posts tells how to create “a” record in CRM from USD, this one involves one interesting Microsoft’s pre-build (careful, I didn’t say OOB 🙂 ) Timer control. This control has the ability to record the total time the session is opened and the total time that the agent spent on this session (Hoping, you already know that USD gives the flexibility to an agent to open multiple sessions at a time and to work with multiple customers at a time).

So, How do you get the Timer control? Simple -Install USD with basic configurations. It has 2 hidden actions

  • GetSessionSeconds – Returns the number of seconds that the agent kept open the session
  • GetSessionUsageInSeconds – Returns the number of seconds that the agent is actively in the session (ie. Not switched to a different session)

Why I said hidden actions is, they will not come to you automatically when you install the USD for some reasons known only to Microsoft :). Not a big deal – Just go and create these actions for the Timer hosted control.

Okay, Theory done – Let’s get into action.

Create Actions for the Timer hosted control

NOTE: This is step is only required if you don’t see the mentioned actions in the Timer hosted control.

1. Navigate to Hosted controls -> Timer Hosted control -> UII Actions, Check if you have above mentioned 2 actions exists or not.

2. If No, Go ahead and create a New UII action

3. Mention name as GetSessionSeconds and hit Save & Close.

4. Repeat the same for GetSessionUsageInSeconds. This is how your timer control actions would look like at the end of this step.

Session Timer Actions - GetSessionSeconds, GetSessionUsageInSeconds
Session Timer Actions

Create an entity to hold the Session history records

5. This is plain CRM process. Go ahead and create an entity with a meaningful name and couple of Integer fields to hold the session time & active time. Here is how my entity looks like

Session History entity
Session History entity

Create Action calls

6. The first action call we are going to create is to get the total session time. Navigate to Settings -> Unified Service desk -> Action calls – > Create new Action call

7. Create an action call with the following information

Field Name Field Value
Name Get Session total time (or any other meaningful name if you want)
Order 10
Hosted Control Timer
Action GetSessionSeconds

8. Create next action for getting active session time as well with the following information

Field Name Field Value
Name Get Session active time (or any other meaningful name if you want)
Order 20
Hosted Control Timer
Action GetSessionUsageInSeconds

9. Now that we have created the action calls required to get the data, we will go ahead and use this data to create a new record. Create a new action call to create a new session history record with the following information

Field Name Field Value
Name Create Session timer record (or any other meaningful name if you want)
Order 30
Hosted Control CRM Global Manager
Action CreateEntity
Data LogicalName=sri_usdsessiontime

sri_name=Session Started by [[$Context.UserDisplayName]+]


sri_sessionendtime=DateTime($Expression(new Date().toLocaleString()))

sri_totalsessiontime=Int($Expression(Math.round([[$Return.Get session Total time]+]/60)))

sri_activesessiontime=Int($Expression(Math.round([[$Return.Get Session active Time]+]/60)))

Some important notes here:

a) Make sure you are changing the entity name and other field names in the Data parameter according to your custom entity name & fields

b) Notice the use of $Return replacement parameters to get the session time & actual time, Any action call that returns output – can be captured from $return replacement parameters.

c) I’m converting the time in minutes by dividing the actual value with 60 and using Math.round to round it. I don’t think you would like to see this information in seconds directly, but it is up to you to convert or not to into minutes

d) To get the Session end time I’m using Javascript’s new Date() method and so to evaluate Javascript values we are using $Expression. You can also see the same in Minute’s conversion as well.

All done, Last step – Wire up the Action calls and Events.

10. The only place that we can get the total session time & active session time is when the user clicks on “Close” button on Session. And the event that fires at that time is “SessionCloseRequested”. So, let’s add all these action calls in the session close requested event as shown below.

SessionCloseRequested Event
image003SessionCloseRequested Event

That’s it, We are done with the configurations part of it. Let’s just test it by opening USD freshly. Start a couple of sessions and wait for few minutes, just play with both the sessions by keeping one active for some time and the other one active for some time. Close the sessions one by on and you should see the result something like shown below.

Hylaa… We just finished one another common business scenario in USD implementations – with absolute 0% coding, which many of my friends out there love :),  Hope you also 🙂 .. !!

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 )

Connecting to %s