Auto close resolved incidents business rule and scheduled item is not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 11:42 PM
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:
System Property:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 07:49 AM
Hi,
the BR runs based on scheduled trigger
If the OOB one runs fine then your should also work fine
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 12:08 AM
Looks fine
gr.setLimit(3); should be fore the loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 12:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 04:38 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 04:45 AM
Make the name of the business rule without any spaces, then it will trigger