On Hold duration calculation

akshaykcc19
Tera Contributor

I have the scenario, to calculate total duration when incident is put on hold and stop the calculation when incident state is inactive like closed or cancel how to achieve this?

 

9 REPLIES 9

When i create new incident  and keept on hold for 5 mins  then  total on hold time taking like 32 days 18 hours

Hi @akshaykcc19 

 

  • If the record left On Hold and returned later, OOB field accumulates all durations.
  • The field is calculated by the “On Hold Duration” timer under the Elapsed Time workflow.

  • It sums all On Hold periods from when the ticket entered On Hold state to the present.

  • So a 5-minute On Hold plus a previous 32-day On Hold will show as 32 days 18 hours total.

Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."

 

Bert_c1
Kilo Patron

The Metrics feature can do what is asked. See:

MetricDefinitionSupport.html

as a starting place.

 

what you are looking for happens OOB. Look at the metric_instance table for records using the following query: definition=35f2b283c0a808ae000b7132cd0a4f55^value=On Hold

(The sys_id is that of the "Incident State Duration" metric the 'incident' table. 

Simran Gadodiya
Mega Sage

Hi @akshaykcc19 
 You can refer following article.


https://www.servicenow.com/community/itsm-forum/calculate-incident-on-hold-duration/m-p/689154

If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Thank You!!

NavinAgarwal
Kilo Guru
You can follow below steps to Implement the Calculation:
 
1. Configure a Metric Definition:
  • Go to Metric Definitions and create a new metric on the incident table. 
  • Set the metric to trigger when the incident's state changes to "On Hold". 
  • Configure a second trigger to capture the time when the state changes from "On Hold" to an active status (e.g., "In Progress").
  • This will record the duration of time the incident spends in the "On Hold" state. 
 
2. Create a Calculated Field on the Incident Table:
  • You can use a Business Rule on the incident table that runs when the incident is closed or cancelled. 
  • Inside the business rule, use the metric definition to sum the total time the incident was in an "On Hold" state.
  • Use a function like gs.dateDiff() to get the total elapsed time from when the incident was created to when it was closed.
  • Subtract the total "On Hold" duration from the total elapsed duration to get the effective resolution time. 
Example Formula (Conceptual, may vary by platform)
Imagine you have:
  • incident.created_at (Date/Time the incident was created)
  • incident.resolved_at (Date/Time the incident was closed or cancelled)
  • total_on_hold_duration (A field that sums all the times the incident was in "On Hold" state, calculated using the metric definition)
Your formula for the effective duration would look something like this:
  • effective_duration = gs.dateDiff(incident.created_at, incident.resolved_at) - total_on_hold_duration 

 

If you found my response helpful, could you please mark it as ‘Accept as Solution’ and ‘Helpful’? This small action goes a long way in helping other community members find the right answers more easily and supports the community.