- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2022 09:37 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2022 09:46 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2022 09:46 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2022 10:19 PM
Hi Harish,
Thank you for the suggestion, with the help of my development team
I created this business rule in my non-prod instance after that I cleared the cache in the system. Also, we ran a background script for this after that It is working fine for new incidents and for old incidents as well, tested for 3 incidents working fine, it is important for us to calculate business duration, thanks for the help within the short time.
Thanks,
Mani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 06:55 PM
hi Harish,
in my case we don’t have sla for the incident but they need business duration how to achieve this .
in previous I created metrics definition on assignment group field and it calculated duration open to resolved . But now they want business duration. Could you please help me
2nd case on request item also I need report
please find attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 08:31 PM
Hi rabbanis,
Please create a business rule in the Metric table based on the schedule(please take sys_id of the schedule), it will work for all tables, not only for incidents. It will work for Request item, Problem, Change etc.
Thanks,
Harish Kota