- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 01:47 AM
Hello ,
Is there a working solution to autoclose incidents after 5 business days excluding weekends and holidays?
I have searched other community topics but any of them not working
The best solution is to created a scheduled job fired daily and checking incidents resolved at date.
Any ideas?
Regards
Marcin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 02:10 AM
You will have to check whether the current date is more than 5 business days of the updated time of the INC
// This script automatically closes incidents that are resolved
// and haven't been updated in the specified number of days.
// This number is a property in System Properties.
// To place a comment in the incident, uncomment the "gr.comments" line.
autoCloseIncidents();
function autoCloseIncidents() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
if (pn > 0) {
var gr = new GlideRecord('incident');
gr.addQuery('incident_state', '6');
//gr.addQuery("number", "INC0000054");
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
var resolvedTime = new GlideDateTime(gr.sys_updated_on);
var days = 5;
var nowDateTime = new GlideDateTime();
var dur = new GlideDuration(60*60*24*1000*days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); // give the sys_id of the schedule which is excluding weekends and holidays
var finalTimeAfter5BusinessDays = schedule.add(resolvedTime, dur);
// check if the 5 business days have crossed
if(nowDateTime.getNumericValue() > finalTimeAfter5BusinessDays.getNumericValue()){
gr.incident_state = '7';
// gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
}
}
}
another approach here
How to Auto-Close Resolved Cases (5 Business Days)
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 01:51 AM
Hi,
Have you seen this ->Configure incidents to close automatically | ServiceNow Docs
This is on oob way to do the same, and it is driven by a scheduled job.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 01:54 AM
Thank you for reply. Yes i have checked that. It doesnt cover holidays . In Scheduled job schedule needs to be queried i think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 02:09 AM
If you see the job you can add a schedule to it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 02:10 AM
You will have to check whether the current date is more than 5 business days of the updated time of the INC
// This script automatically closes incidents that are resolved
// and haven't been updated in the specified number of days.
// This number is a property in System Properties.
// To place a comment in the incident, uncomment the "gr.comments" line.
autoCloseIncidents();
function autoCloseIncidents() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
if (pn > 0) {
var gr = new GlideRecord('incident');
gr.addQuery('incident_state', '6');
//gr.addQuery("number", "INC0000054");
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
var resolvedTime = new GlideDateTime(gr.sys_updated_on);
var days = 5;
var nowDateTime = new GlideDateTime();
var dur = new GlideDuration(60*60*24*1000*days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); // give the sys_id of the schedule which is excluding weekends and holidays
var finalTimeAfter5BusinessDays = schedule.add(resolvedTime, dur);
// check if the 5 business days have crossed
if(nowDateTime.getNumericValue() > finalTimeAfter5BusinessDays.getNumericValue()){
gr.incident_state = '7';
// gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
}
}
}
another approach here
How to Auto-Close Resolved Cases (5 Business Days)
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader