Need help displaying the time an Agent has spent in their Current Presence State in AWS

AlexanderDitzig
Tera Contributor

Hello all,

 

I currently working on a project for client and I'm having a bit of trouble with one of their specifications. Management would like to see how long any Agent has spent in their Current Presence State on a list on the landing page. I can get this value to show up on the backend of ServiceNow, but it always loads as (empty) on the Landing Page.

 

My process is done in two parts. First by an onChange Client Script that captures the time of the most recent change to the Current Presence State field. Written as such...

 

function onChange(control, oldValue, newValue, isLoading){
if (newValue == oldValue) {
return;
}
var today_date = new Date();
var today_date_time = formatDate(today_date, g_user_date_time_format);
g_form.setValue('u_time_last_state_change', today_date_time);
}

 

After which I use a display Business Rule to populate a field with the amount of time since that change using the following script...

 

(function executeRule(current, previous /*null when async*/) {
var d1 = new GlideDateTime();
var d2 = new GlideDateTime(current.u_time_last_state_change);
var r = GlideDateTime.subtract(d2, d1);
current.u_time_in_state = r.getDisplayValue();
})(current, previous);

0 REPLIES 0