This blog explains about how to 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'
Step 1 : Create a Schedule Item as shown below
Step 2 : Create a Business Rule as shown below
// 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'
Thank you it's good information on servicenow online training
ReplyDeleteI really appreciate information shared above. It’s of great help.
ReplyDeleteservicenow online training
Hi,
ReplyDeleteThis is something worth sharing. I am amazed to see how well you organized this post. your blog style is also very impressive and beautiful.Onemore thing is Can you provide serviceNow online training.....? please reply me
Thank you