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

Sarabjeet1
Tera Contributor

@Ankur Bawiskar Please help.

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

James Chun
Kilo Patron

Hi @Sarabjeet1,

 

What is the label of the state where the value = 50?

A few things to check:

  • Use an integer for setting the 'state'. i.e. gr.state = 50;
  • Is '50' part of the RITM's 'state' close_states attribute?
  • Are you saying it's only a few RITMs that are triggered again? If so, how are they different from those who didn't? e.g. check the fields' values such as the 'active', 'state', and etc

Cheers

Hi James,

1. The label for 50 is closed.

2. yes it is part of RITM's 'state' attributes.

3. I found no difference or change . These workflow are not new and were perfectly fine.