Run a duration field when incident is created and comlete when closed

sunil kumar6
Tera Contributor

we want to create a duration field which runs from 6am to 6pm monday to friday once incident is created and completes when incident is resolved

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sunil kumar6 

 

Are you referring to SLA? 

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

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Not sla but a field called age to calculate incident duration and this should run only from 6am to 6pm monday to friday

Najmuddin Mohd
Mega Sage

Hi @sunil kumar6 ,
One way is to get the complete duration when an incident is Completed (resolved / Closed) using a Schedule in a business rule.

First create a schedule from 6am to 6pm Monday and Friday, and call the schedule in the business rule.

var startDate = new GlideDateTime(current.sys_created_on);
var endDate = new GlideDateTime(); // current time when business rule is triggered (condition state is closed/resolved)





var schedule = new GlideSchedule();
schedule.load('  '); // loads "6am-6pm weekdays excluding holidays" schedule (sys_id of the schedule)
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule

Update the custom field with duration.getDurationValue();



Hope this helps.

Regards,
Najmuddin.

 

Hello Najmuddin,

 

i have tried this script its not calculating the duration.