Auto Close Incident after 5 days of resolution only for P1/P2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Currently incident is auto-closed after 3 days of resolution in ServiceNow. Want to know if it is technically feasible to have a 5 days auto-closure set only for P1/P2 incidents and not for all.
There is OOO system property ''glide.ui.autoclose.time" (attaching the screenshot for reference). This property is not set for any specific priority.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @SanikaK ,
As you are correctly pointed, OOB autoclose set up is applicable for incident excluding major incident INC ticket.
The same situation we went through long back and got Support's reply that no oob configuration is not in place on it ->we can do customization on that.
We ran a fix script to auto close legacy data once in prod and scheduled with specific filters (only for P1/P2), so that after mentioned days for resolved tickets ->script can close the ticket.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hi @SanikaK ,
For this business need, you need to replicate the OOTB functionality and customize as per your need.
Check the following objects for more details and update accordingly.
Scheduled Job = Autoclose Incidents, this job is triggering this business rule "incident autoclose" and this BR is reading that system property for auto closer day(s).
You can copy the scheduled job with new name, copy the BR with new name and update the scheduled job with new BR name. Create new system property for 5 days and use the same in new BR. ( just keep this logic separate without updating the existing code )
BR with P1/P2 filter condition
Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Out of the box there is no property/config which says only P1/P2 incidents can be auto-resolve or days can be separated based on Priority
you will have to update the OOTB business rule "incident autoclose" anyhow
Separate out via functions
// 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.
autoCloseIncidentsExceptP1P2(); // handle other than P1 and P2
autoCloseIncidentsP1P2(); // handle P1 and P2
function autoCloseIncidentsExceptP1P2() {
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', IncidentState.RESOLVED);
gr.addQuery('priorityNOT IN1,2');
if (gs.getProperty('com.snc.incident.autoclose.basedon.resolved_at', 'false') === 'true') {
gr.addQuery('resolved_at', '<', queryTime);
}
else {
gr.addQuery('sys_updated_on', '<', queryTime);
}
if (pm.isActive('com.snc.incident.mim')) {
var mim = gr.addNullQuery('major_incident_state');
mim.addOrCondition('major_incident_state', '!=', new sn_major_inc_mgmt.MajorIncidentTriggerRulesSNC().MAJOR_INCIDENT_STATE.ACCEPTED);
}
// Exclude OT Incident and its children being affected by this script
if (pm.isActive('com.sn_ot_inc_mgmt')) {
gr.addEncodedQuery('sys_class_nameNOT IN' + new TableUtils('sn_ot_incident').getAllExtensions().toArray().join());
}
gr.query();
while(gr.next()) {
gr.incident_state = IncidentState.CLOSED;
gr.state = IncidentState.CLOSED;
// gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.closed_by = gr.resolved_by;
gr.update();
}
}
}
function autoCloseIncidentsP1P2() {
var ps = 5;
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
if (pn > 0) {
var gr = new GlideRecord('incident');
gr.addQuery('incident_state', IncidentState.RESOLVED);
gr.addQuery('priorityIN1,2');
if (gs.getProperty('com.snc.incident.autoclose.basedon.resolved_at', 'false') === 'true') {
gr.addQuery('resolved_at', '<', queryTime);
}
else {
gr.addQuery('sys_updated_on', '<', queryTime);
}
if (pm.isActive('com.snc.incident.mim')) {
var mim = gr.addNullQuery('major_incident_state');
mim.addOrCondition('major_incident_state', '!=', new sn_major_inc_mgmt.MajorIncidentTriggerRulesSNC().MAJOR_INCIDENT_STATE.ACCEPTED);
}
// Exclude OT Incident and its children being affected by this script
if (pm.isActive('com.sn_ot_inc_mgmt')) {
gr.addEncodedQuery('sys_class_nameNOT IN' + new TableUtils('sn_ot_incident').getAllExtensions().toArray().join());
}
gr.query();
while(gr.next()) {
gr.incident_state = IncidentState.CLOSED;
gr.state = IncidentState.CLOSED;
// gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.closed_by = gr.resolved_by;
gr.update();
}
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
