How to calculate OOTB Business Duration in Incident Metrics

Manikanta G
Tera Contributor

Hi Guys,

 

How to calculate the OOTB Business Duration field in Incident Metrics, I have checked in Incident Metrics only the Duration field is calculated, not Business Duration. I want to Calculate Business Duration as well and only in the scheduled SLA, Duration field is calculating 24/7 not in the SLA Scheduled timelines.

 

I am new to ServiceNow, working in support, and need someone's expertise on how to enable/calculate the Business duration field. Is any Property, Script required for this?

 

Thanks,

Mani

1 ACCEPTED SOLUTION

Harish Kota
Kilo Sage

Hi Manikanta,

This can achieve by using before business rule, please make sure you can create this in your non-prod instance and test, as you mentioned you are working in support, please check with your development team as well on this and proceed.

 

Business Rule:

When to Run: Before - Insert and update

 

Advanced Script:
(function executeRule(current, previous /*null when async*/ ) {

// Add your code here
var gr = new GlideRecord("metric_instance");
gr.addEncodedQuery('end!=NULL^business_duration=NULL');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while (gr.next()) {
var gsBusiness = new GlideSchedule('sys_id'); //update sys_id of your schedule
// Get duration based on schedule
gr.business_duration = gsBusiness.duration(gr.start.getGlideObject(), gr.end.getGlideObject());
gr.setWorkflow(false);
gr.update();
}

})(current, previous);

 

 

Thanks,

Harish Kota

 

Please hit like or Accept the solution if it works for you.

View solution in original post

5 REPLIES 5

Hi @Harish Kota, can you please help to clarify on which table do we need to write the business rule? Is it metric instance table or the incident/request/problem table on which the metric definition is created?

 

Regards,

Chandan