How to Auto Close ‘Resolved’ Incidents after 7 days in Service Now
This blog explains how to auto close any ‘Resolved’ incidents after ‘certain (7 days)’ period of time.
Step 1 : Create a Schedule Item as shown below
Step 2 : Create a Business Rule as shown below
Step 3 : Write below script in ‘Advanced’ tab of above business rule
// 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.autocloseincident.time’);
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
if (pn > 0) {
var gr = new GlideRecord(‘incident’);
gr.addQuery(‘state’, 6);
// gr.addQuery(‘sys_updated_on’, ‘<’, queryTime);
gr.addQuery(‘sys_updated_on’, ‘<’, gs.daysAgo(pn));
gr.query();
while(gr.next()) {
gr.state = 7;
// gr.comments = ‘Incident automatically closed after ‘ + pn + ‘ days in the Resolved state.’;
gr.active = false;
gr.closed_by = gr.resolved_by;
gr.update();
}
}
}
Step 4 : Create below System Property (sys_properties.list) for glide.ui.autocloseincident.time
Schedule Script triggers above business rule every hour and find out any ‘Resolved’ Incident more than 7 days, it will change the state to ‘Closed’
About Ravi Kumar:
Ravi Polishetty (ravi@fortuneminds.com) is an IT Expert covering 15+ years of experience in design/architect/developing Enterprise and Cloud-based Applications; as well as working on IT and Software projects for the top Fortune 1,000 companies using ServiceNow, Oracle Fusion Middleware, and Java/J2EE technologies. He is also a ServiceNow SME with a versatile set of experience in the Design, Development, and Implementation of ServiceNow Applications.