Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Exclude P1 and P2 Incidents from Auto closure

DREX
Tera Contributor

Hi All,

 

I have a requirement of excluding Priority 1 and Priority 2 tickets from auto-closure. I tried adding filter condition in the Business Rule but it still closed P1 and P2 incidents.

 

Business Rule Name : incident autoclose

Condition : Priority is not P1 or P2

 

script:

// 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', IncidentState.RESOLVED);
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 anyone can help

 

1 ACCEPTED SOLUTION

Quinten
Tera Guru

Right below the following line:

var gr = new GlideRecord('incident');

add the following line

gr.addQuery('priority', 'NOT IN', '1,2');

This tells the script to only target Incidents for which the priority is NOT 1 or 2.

View solution in original post

3 REPLIES 3

Quinten
Tera Guru

Right below the following line:

var gr = new GlideRecord('incident');

add the following line

gr.addQuery('priority', 'NOT IN', '1,2');

This tells the script to only target Incidents for which the priority is NOT 1 or 2.

DREX
Tera Contributor

Thanks for the help!!

Community Alums
Not applicable

Hi Drex, i know that this is an old post, but was this solution working for you?