RITM auto close script triggered the workflow again for closed RITMs

Sarabjeet1
Tera Contributor

Hi,

 

I created a scheduled job to auto close the resolved RITMs. PFB the script. But when this script was executed it triggered the workflow again for most of the resolved RITMs and because of that all the related task are created again. Please let me know what i did wrong.

 
Scheduled job
 
autoCloseRITM();

function autoCloseRITM() {
    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', 10);
        if (gs.getProperty('com.snc.incident.autoclose.basedon.resolved_at', 'false') === 'true') {
            gr.addQuery('u_resolved', '<', queryTime);
   
        } else {
            gr.addQuery('sys_updated_on', '<', queryTime);
        }
        gr.query();
        while (gr.next()) {
            gr.state = '50';
            gr.active = false;
            gr.closed_by = gr.resolved_by;
            gr.comments = 'Deemed Successful and Auto closed';
            gr.update();
        }
    }
}
1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Sarabjeet1 ,

 

Try gr.setWorkflow(false) before gr.update() line.

This will stop any workflow or BR to execute when u r executing ur script.

 

Thanks,

Danish

View solution in original post

5 REPLIES 5

Hi @Sarabjeet1,

 

Since the 'state' field is an integer type, you should change the script from gr.state = '50'; to gr.state = 50;

 

In regards to the second point, I was referring to the 'close_state' attribute, something like the below:

JamesChun_0-1713683893545.png

If the 'close_states' attribute has been configured properly, there is no need to have the following line of code - gr.active = false;

 

In regards to #3, are you referring to the Workflow version? What I meant was, if the workflow is re-triggered for some RITMs only, compare the field values of RITMs (such as active field, state field, etc) to the other RITMs where the workflow was not re-triggered. By doing so, you can identify why those workflows were re-triggered and identify the root cause.

 

Hope that makes sense.