- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2024 03:03 AM
I've requirement, in which I need to close the resolved cases after 3 business days.
But while doing that we need to consider the Business Hrs. are 8-5 and excluding weekends.
I was trying using scheduled job, it is working but including weekends and 24/7
Please let me know if anyone have solution for this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2024 03:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2024 03:23 AM - edited ‎11-26-2024 03:54 AM
Hi @AishwaryaS1 ,
Try using below script in your schedule job.
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
if(pn > 0){
//Get a schedule by name to calculate duration
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', '8-5 weekdays excluding holidays');
if (typeof GlideSchedule != 'undefined')
var sched = new GlideSchedule(schedRec.sys_id);
else
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
//Get the current date/time in correct format for duration calculation
var actualDateTime = new GlideDateTime();
actualDateTime.setDisplayValue(gs.nowDateTime());
//Query for resolved incident records
var gr = new GlideRecord('incident');
gr.addQuery('state', 6);
gr.query();
while(gr.next()){
//Close any records that have not been updated in 'pn' number of hours
//Date difference calculated based on specified schedule
var difDay = sched.duration(gr.sys_updated_on.getGlideObject(), actualDateTime).getDayPart()*24;
var difHour = sched.duration(gr.sys_updated_on.getGlideObject(), actualDateTime).getDurationValue().split(':')[0].substr(-2);
var dif = difDay + parseInt(difHour.replace(/^[0]+/g,""));
if(dif >= pn){
gr.state = 7;
gr.active = false;
//gr.comments = 'Incident automatically closed after ' + pn + ' hours in the Resolved state.';
gr.update();
}
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2024 04:49 AM
@Runjay Patel I tried this solution, but it is not working as expected. I want to close the resolved cases after 3 business days. Suppose case is resolved on Thursday then it should be closed on Tuesday not on Sunday.
I need to do this using scheduled job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2024 07:11 AM
Hi @AishwaryaS1 ,
I have given you working code, you just need to create schedule which includes holidays and run only weekdays.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2024 03:53 AM