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.

Auto close Requested Items

Wayne Richmond
Tera Guru

I am trying to create a Business Rule that auto closes Requested Items (we ignore Requests) if they have not been updated whilst in a Resolved state for 5 days. There is a BR for Incidents which works fine, using the System Property 'glide.ui.autoclose.time'. I tried to recreate this script for ReqItems but it just doesn't work. Here is the code:



// This script automatically closes request items that are resolved
// and haven't been updated in the specified number of days.

autoCloseReqItems();

function autoCloseReqItems() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);

if (pn > 0) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', '4');
gr.addQuery('u_review_required', 'false');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
gr.query();
while(gr.next()) {
gr.state = '3';
gr.comments = 'Request automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
}
}


Any ideas why this doesn't work?

7 REPLIES 7

neetusingh
Giga Guru

Yes, there must be a scheduled job which should trigger this BR.


Wayne Richmond
Tera Guru

Thank you both, that has worked a treat! Great response as always, thanks.


rachelconstanti
Mega Sage

What do I need to do to auto close if they have not been approved?