Run a duration field when incident is created and comlete when closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2024 02:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2024 02:24 AM
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2024 02:31 AM
Not sla but a field called age to calculate incident duration and this should run only from 6am to 6pm monday to friday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2024 04:21 AM - edited ‎08-30-2024 04:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2024 02:00 AM
Hello Najmuddin,
i have tried this script its not calculating the duration.