Reporting on time in "Awaiting User Info" / Pause duration

John Reynolds
Mega Expert

Hello,

I have a requirement to capture and report on how long an incident has been in the state of "Awaiting User Info" (value 4).   I have created two business rules on update when state changes to and from Awaiting User Info to populate two fields.   The first BR populates a date/time field "u_paused_at" when state changes TO Awaiting User Info.

(function executeRule(current, previous /*null when async*/) {

current.u_pause_at = gs.nowDateTime();

})(current, previous);

The second BR populates the duration field "u_pause_duration" by taking the value in "u_paused_at" and comparing it to the current gs.DateTime in seconds.

(function executeRule(current, previous /*null when async*/) {

if (current.u_pause_duration.nil()) {  

      // Calculate the duration from u_pause_at

      current.u_pause_duration = gs.dateDiff(current.u_pause_at.getDisplayValue(), gs.nowDateTime(), false);  

} else {  

      // Calculate the duration in seconds from u_pause_at, then add it to the existing total  

      var seconds = gs.dateDiff(current.u_pause_at.getDisplayValue(), gs.nowDateTime(), true);  

      var gdt = new GlideDateTime(current.u_pause_duration);  

      gdt.addSeconds(seconds);  

      current.u_pause_duration = gdt.getTime();

}  

current.u_pause_at = '';  

})(current, previous);

These both work as expected, capturing the information on respective change of the state, however, we also need to be able to have a "live" report that shows this information.   For example, in order to actually see how long the ticket was paused currently, we need to change the state and it updates the duration field.  

How can I keep the "u_pause_duration" field as up to the minute as possible?   Would a scheduled script that runs periodically (every 5 minutes or so) work where it queries all active incidents with state of "Awaiting User Info" and updates the duration field?   Is there a better solution?

Thanks!

6 REPLIES 6

Valentina6
Giga Guru

Hi John,


I guess you don't need to create business rule to get the duration, there is already a metric that tracks it and called 'Incident State Duration'. You can report on the metric instance table, filtering by metric definition and value = 'Awaiting User Info'.



Hope it helps!



Regards


Valentina


Thanks Valentina, however this will only show me the information for when an incident has moved out of the Awaiting User Info state.   It does not show me the current length of time an incident has been in Awaiting User Info state.


I would like to create a new report to identify Awaiting user ticket closure date or need to know when the ticket will be closed. please help me

kristenankeny
Tera Guru

I'd use a display business rule, since it will update the data anytime the record is loaded for display (reports, lists, form).