Current State Duration

Amy Lind1
Giga Guru

Greetings!  

I'm posting because I'm certain this data has to have been collected by some of you out there.   I've several ideas in my head, but why reinvent the wheel if I poll you all?  

So, what we need is the and that is the current state duration.   We are using the standard metrics to pull how long an Incident was in each state in the past, however the data we are missing is being able to report how long Incidents have been sitting in the state they are currently in.   Up to this point, we've been exporting the data and creating our own reports to calculate the duration from which the Incident was last updated to the current date, which is less than ideal.  

Any thoughts/suggestions on how we can accomplish this?

Many thanks!   Amy

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

This can come with a bit of load consequence, but its the only way I know of to accomplish it.


We had a similar requirement.   They wanted all active calculations to be "as up to date as possible" rather than being null until the calculation completed.



I created a scheduled job that runs every 12 hours.   It checks all Metric Instances where calculation_complete = false and updates their duration field.   If I were to do it over again, I might add a field to the Metric Definition table which governs whether or not we want the metric instances caught in this script (its essential for some metrics, but not for others).



Scheduled Job:   "Update Continuous Duration Metrics"


var inst = new GlideRecord("metric_instance");


inst.addQuery('definition.type','field_value_duration');


inst.addQuery('calculation_complete',false);


inst.query();



while(inst.next()){


  inst.duration = gs.dateDiff(inst.start.getDisplayValue(), gs.nowDateTime());


}


View solution in original post

6 REPLIES 6

Gayathri24
Giga Contributor

Hi Amy Lind,


Did you find any solution for this?


Uncle Rob
Kilo Patron

This can come with a bit of load consequence, but its the only way I know of to accomplish it.


We had a similar requirement.   They wanted all active calculations to be "as up to date as possible" rather than being null until the calculation completed.



I created a scheduled job that runs every 12 hours.   It checks all Metric Instances where calculation_complete = false and updates their duration field.   If I were to do it over again, I might add a field to the Metric Definition table which governs whether or not we want the metric instances caught in this script (its essential for some metrics, but not for others).



Scheduled Job:   "Update Continuous Duration Metrics"


var inst = new GlideRecord("metric_instance");


inst.addQuery('definition.type','field_value_duration');


inst.addQuery('calculation_complete',false);


inst.query();



while(inst.next()){


  inst.duration = gs.dateDiff(inst.start.getDisplayValue(), gs.nowDateTime());


}


Hi Robert, the above script is very helpful. I scheduled job and tested this out for one of the metrics i created - ticket state duration but am not seeing the business duration or duration field populated after executing the job several times (see screenshot attached). My overall goal is to report on how long a ticket (incident or sc_task) is in the on hold or pending status. Let me know if I'm missing something? Thanks in advance.

Hi Robert, the above script is very helpful. I scheduled job and tested this out for one of the metrics i created - ticket state duration but am not seeing the business duration or duration field populated after executing the job several times (see screenshot attached). My overall goal is to report on how long a ticket (incident or sc_task) is in the on hold or pending status. Let me know if I'm missing something? Thanks in advance.