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

Thanks - I changed it to a display business rule that runs on query.   It is working perfectly on form view, however when attempting to run a report and in list view, it is not displaying the Pause duration.   No changes made to the BR besides changing display rules.



find_real_file.png



find_real_file.png

From what I'm seeing here, you may need to utilize g_scratchpad to ensure that the data you are dependent on is available client side when doing this from a report.



https://developer.servicenow.com/app.do#!/lp/servicenow_administrator/app_store_learnv2_scripting_is...



This community post has more information on how to do this:



ScratchPad and Display Business rule