Auto close resolved incidents business rule and scheduled item is not working as expected

Roxi1
Tera Contributor

We have defined business rule, scheduled item, and system property to auto close the particular resolved incidents, but not closing the incidents and not getting any logs in system logs. can someone please help on it. here am pasting BR, schedueld item, and system property. for testing purpose we can not wait for days. is there any way that we can set some minutes.

after BR:

(function executeRule(current, previous /*null when async*/) {

// Add your code here
autoCloseIncidents();

function autoCloseIncidents() {
var ps = gs.getProperty('glide.ui.securityincidentautoclose.time');
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
//queryTime.addSeconds(-pn);

if (pn > 0) {
var gr = new GlideRecord('incident');
gr.addEncodedQuery('category=IT Security^u_security_incident_stateNOT INproposed,accepted,rejected^incident_state=6');
// gr.addQuery('sys_updated_on', '<', queryTime);
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
gr.state = 7;
gr.setLimit(3);
gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.work_notes="Auto closed resolved incidents through Business rule";
gr.closed_by = gr.resolved_by;
gs.log("The resolved incidents are closed");
gr.update();
}
}
}
});

scheduled item:

find_real_file.png

System Property:

find_real_file.png

10 REPLIES 10

Hi,

the BR runs based on scheduled trigger

If the OOB one runs fine then your should also work fine

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

suvro
Mega Sage
Mega Sage

Looks fine

gr.setLimit(3); should be fore the loop

suvro
Mega Sage
Mega Sage

I hope Business Rule name matches the script name below

find_real_file.png

Try to keep logs in between the code, so that you get to know, where it is getting stuck

Roxi1
Tera Contributor

it seems no log is getting generated in system logs, means the BR itself is not triggering. can you please help me why this BR is not getting triggered

Make the name of the business rule without any spaces, then it will trigger