- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:37 PM
Hello Team,
I'm trying to set auto close a request after 7 days. I have written business rule and schedule job but didn't worked can any one help me how to close the request.
Scheduled Job :
var gr = new GlideRecord('table name');
gr.addEncodedQuery(query);
gr.query();
gr.state = '5'; //set the state to closed
gr.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:52 PM
I have the same
1. Create BR: When to run is after but without any condition
and the script. This request have the same time with incident. if you want to change it, just add your time in var ps = 7;
autoCloseRequest();
function autoCloseRequest() {
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('sc_req_item');
gr.addQuery('state', '5');
gr.addQuery('sys_updated_on', '<', queryTime);
gr.addQuery('u_coh', 'false');
while (gr.next()) {
gr.state = '3';
gr.comments = 'Request ditutup otomatis setelah ' + pn + ' hari dari tiket diselesaikan.';
gr.active = false;
gr.update();
}
}
}
And then create the scheduled job. fcScriptName=request autoclose, is the BR that create before. and it will run every 1 hour.
this is working fine in the instance. hope this will give you little help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 09:18 PM
Hi
Step 1
Business rule name : RITM autoclose
After BR on sc_req_item table
autoCloseRITMs();
function autoCloseRITMs() {
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('sc_req_item');
gr.addQuery('sys_updated_on', '<', queryTime);
gr.query();
while(gr.next()) {
gr.state = 3;
gr.comments = 'RITM automatically closed after ' + pn + ' days without any update on the RITM record.';
gr.active = false;
gr.closed_by = gr.resolved_by;
gr.update();
}
}
}
Step2
Scheduled Job
Mark ✅ Correct if my response solves your issue and also mark 👍 Helpful if you find my answer helps you based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 09:24 PM