How to auto close Requested item after 7 days same as incident

Chaitanya Redd1
Tera Guru

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 query = 'state=4^sys_updated_onRELATIVELT@dayofweek@ago@7'; //state is resolved
var gr = new GlideRecord('table name');
gr.addEncodedQuery(query);
gr.query();
while(gr.next()){
gr.state = '5'; //set the state to closed
gr.update();
}
 
Business rule is same as incident one for autoclose.
 
Thanks,
Chaitanya
1 ACCEPTED SOLUTION

zulhiyatiuwi
Tera Expert

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.

View solution in original post

6 REPLIES 6

Shantharao
Kilo Sage

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

find_real_file.png

Mark Correct if my response solves your issue and also mark 👍 Helpful if you find my answer helps you based on the impact.