Calculate state duration

Rishabh Dev Kha
Tera Contributor

Hi,

 

I want to calculate total time for which incident is on "In Progress" state how can  I do it.I tried it with metric but it is creating seperate record if state changes from to another.

4 REPLIES 4

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,

You can use metric table in reporting module.
Below is one similar report.

 

SaurabhGupta_1-1673129286853.png

 


Thanks and Regards,

Saurabh Gupta

AndersBGS
Tera Patron
Tera Patron

Hi @Rishabh Dev Kha ,

 

Have you looket into SLA breakdown as a possibility? https://docs.servicenow.com/en-US/bundle/tokyo-it-service-management/page/product/service-level-mana...

if my answer helped for a answering your question, please my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

-O-
Kilo Patron
Kilo Patron

Easiest is to configure a new Metric Definition. You can find it in the ServiceNow Navigator under Metrics -> Definition. There already is a Metric Definition for the Incident state field. You could create a new one but for field State. After that you can report on it as @Saurabh Gupta suggests.

Note that this will not create records for past incidents but only for future incidents. If you also need historic data, your accessible option is generating it using a Fix script that leverages the sn_hw.HistoryWalker() API - it enables accessing all records (with auditing enabled) with each of that record's state. You would need to create a script that loops through each incident then loops through each update of individual incidents and - of course - compute the length of state and save it as a Metric Instance record.

Below is something I just created (by copying the existing Metric for field Incident state) - you can see that it already captured values as I played with an incident in my PDI:

2023-01-08-1.png

 

Bernard7
Tera Contributor

Someone (more skilled than me, but sorry I don't remember who) already answered: "use OOTB Incident State Duration". So I tested it and it works but the result (attached to this post) only gives past durations where the incident ticket was in State "On Hold" (for instance, but you can select another state in Value field of the report) and now in another State.

 

And you neither get the present duration of a ticket that is presently in the State "On Hold" from the moment the ticket passed to "On Hold" and the moment of the execution of the report, nor the cumulated durations of all moments the ticket passed to the State "On Hold".

 

I saw solutions based on scripting, but I'm looking for something more OOTB without coding.