Business resolve time

brianlan25
Kilo Patron

There is a filed called business duration on the task [task] table. It looks like it gets set a resolution. Does anybody know if this field takes into account hold time or is it strictly calculating the time between Opened and Resolved? 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@brianlan25 

I couldn't find any BR on task table which sets this

In context of INC, there are 2 OOTB BR and both don't consider hold time

55.png

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Tanushree Maiti
Kilo Patron

Hi @brianlan25 

 

Refer KB: KB0780039 How Duration and Business Duration fields are calculated 

                & Scheduled Job to calculate Business Duration and Duration field on TASK

 

How business duration is calculated

The mark_resolved and mark_closed business rules use the legacy API calDateDiff. The calDateDiff function calculates duration using:

  • The first calendar from the sys_calendar table
  • The session time zone of the user who resolves or closes the record

Important: Because the calculation uses the resolver's time zone, results may appear incorrect when viewed from a different time zone. To verify calculations, impersonate the user who resolved or closed the record.

Calculation examples

The following examples demonstrate how business duration is calculated based on the resolver's time zone and the calendar business hours.

Example 1: Incident opened and resolved outside business hours

FieldValue

Opened at

2022-11-09 08:36:30 (London)

Resolved at

2022-11-09 08:39:38 (London)

Resolved by time zone

Europe/London

Calendar business hours

Wednesday 5 PM – 1 AM (London)

Business duration result

0

Explanation: The incident was opened and resolved between 8:36 AM and 8:39 AM London time, which is outside the calendar business hours of 5 PM to 1 AM. Therefore, the business duration is 0.

 

Example 2: Incident spans business hours

FieldValue

Opened at

2022-11-08 08:49:47 (London)

Resolved at

2022-11-09 08:50:14 (London)

Resolved by time zone

Europe/London

Calendar business hours

Tuesday 5 PM – 1 AM (London)

Business duration result

8 hours

Calculation breakdown:

  • From 2022-11-08 08:49:47 AM to 2022-11-08 05:00:00 PM = 0 hours (outside business hours)
  • From 2022-11-08 05:00:00 PM to 2022-11-09 01:00:00 AM = 8 hours (within business hours)
  • From 2022-11-09 01:00:00 AM to 2022-11-09 08:50:14 AM = 0 hours (outside business hours)
  • Total: 0 + 8 + 0 = 8 hours

 

Example 3: Different time zone

FieldValue

Opened at

2022-11-07 16:41:27 (Madrid)

Resolved at

2022-11-07 16:43:58 (Madrid)

Resolved by time zone

Europe/Madrid

Calendar business hours

Wednesday 6 PM – 2 AM (Madrid)

Business duration result

0

Verify business duration calculations

Use the following script to verify business duration calculations for specific opened and resolved date/times.

Before you begin: Change your user time zone to match the time zone of the user who resolved or closed the record.

var opened = new GlideDateTime('2022-11-07 15:41:27'); gs.info(opened.getDisplayValue());

var resolved = new GlideDateTime('2022-11-07 15:43:58'); gs.info(resolved.getDisplayValue());

gs.info(gs.calDateDiff(opened.getDisplayValue(), resolved.getDisplayValue(), false));

Note: Replace the date/time values with the opened_at and resolved_at values from the record you want to verify.

Calculate business duration using a schedule

To calculate business duration based on a schedule instead of a calendar, replace the calDateDiff function in the mark_closed and mark_resolved business rules with schedule-based logic.

  1. Create a schedule or identify an existing base system schedule to use.
  2. Select a time zone for the schedule that is appropriate for your environment. For example, defining US/Pacific ensures that the duration is calculated according to the schedule spans applied in the US/Pacific time zone.
  3. Copy the sys_id of the chosen schedule.
  4. Modify the mark_closed and mark_resolved business rules to use the following script:
// Default Workday 8-5 Floating schedule. Replace with sys_id of the schedule to be used 
var schedule = new GlideSchedule("38f8b6d2c0a801640075da0e39d47696"); 
 
// Use closed_at for "mark_closed" business rule and resolved_at for "mark_resolved" business rule 
var duration = schedule.duration(current.opened_at.getGlideObject(), current.closed_at.getGlideObject()); 
 
// Stores value as a GlideDuration 
current.business_duration = duration; 
 
// Stores value in seconds. The numeric value function returns a value in milliseconds, hence divide by 1000 
current.business_stc = duration.getNumericValue() / 1000; 
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@brianlan25 

I couldn't find any BR on task table which sets this

In context of INC, there are 2 OOTB BR and both don't consider hold time

55.png

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Strange according to this it would update on both resolved and closed. However when I look at incident history it is only doing it on resolved. I'm looking for a way to get average MTTR in performance analytics. We want it to get closed incidents but have the measurement follow opened -> resolved. It looks like there is potential for incidents being closed to update this field.