The Zurich release has arrived! Interested in new features and functionalities? Click here for more

auto close ritm

Sarabjeet1
Tera Contributor

Hi,

 

I need to set a rule for auto closing RITMs after 3 days of resolving. Below is the BR i am using. Please let me know why is it not working.

 

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

autoCloseRequest();

function autoCloseRequest() {
    var ps = gs.getProperty('glide.ui.autoclose.time'); // property value set to 3
    var pn = parseInt(ps);
    var queryTime = new GlideDateTime();
    queryTime.addDaysUTC(-pn);

    if (pn > 0) {
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('state', '10');
        gr.addQuery('sys_updated_on', '<', queryTime);
        gr.addQuery('u_coh', 'false');
        while (gr.next()) {
            gr.state = '50';
            gr.comments = 'Request ditutup otomatis setelah ' + pn + ' hari dari tiket diselesaikan.';
            gr.active = false;
            gr.update();
        }
    }
}

})(current, previous);
1 ACCEPTED SOLUTION

Hi,

Have you created the schedule job to trigger your script?

Like below:

Navigate to sys_trigger table list and search for Autoclose Incident job.

 

Screenshot 2024-01-03 at 4.47.21 PM.png

 

replace name of your BR in the Job Context.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

7 REPLIES 7

Anil Lande
Kilo Patron

Hi,

Have you created a schedule job to run daily?

Check the configurations for incident auto close functionality.

Update your script as given below:

function autoCloseRequest() {
    var ps = gs.getProperty('glide.ui.autoclose.time'); // property value set to 3
    var pn = parseInt(ps);
    var queryTime = new GlideDateTime();
    queryTime.addDaysUTC(-pn);

    if (pn > 0) {
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('state', '10');
        gr.addQuery('sys_updated_on', '<', queryTime);
        gr.addQuery('u_coh', 'false');
gr.query();   // this line was missing
        while (gr.next()) {
            gr.state = '50';
            gr.comments = 'Request ditutup otomatis setelah ' + pn + ' hari dari tiket diselesaikan.';
            gr.active = false;
            gr.update();
        }
    }
}

})(current, previous);
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

Thanks for your response. I edited the code as given by you but it's still not working.

Hi,

Have you created the schedule job to trigger your script?

Like below:

Navigate to sys_trigger table list and search for Autoclose Incident job.

 

Screenshot 2024-01-03 at 4.47.21 PM.png

 

replace name of your BR in the Job Context.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

Thanks for the help. I was not creating scheduled job correctly.