RITM should get close once all catalog tasks are closed

tulasi8
Tera Contributor

Hi Community,

 

I want the RITM should get close only once all the catalog tasks are closed. I have written the business rule for this after update with the condition as state is closed complete.  But it's not working as per requirement. Can anyone please help on this. 

 

    var gr = new GlideRecord("sc_task");
    gr.addActiveQuery();
    gr.addQuery("request_item", current.request_item);
    gr.setLimit(1);
    gr.query();
    if (!gr.hasNext()) {
        var ritm = current.request_item.getRefRecord();
        ritm.state = current.state;
        ritm.update();
    }
 
Thanks,
Tulasi.
15 REPLIES 15

Hello @tulasi8 

 

At action number 61, if you're setting the RITM state as "closed complete" and then ending the flow, remove actions 60 and 61. Instead, outside of the "If" block (action number 54), use the "Look up records" action as per my reply.

 

Please mark this response as Correct and Helpful if it assists you.


Thanks,
Ashish

 

 

Hey @tulasi8, hope you are doing well.

 

Have you tried my solution? Let me know if it doesn't work. If it does, please mark it as 'Helpful' and 'Accept' it as a solution, then close the thread so that future community readers can use it.

 

Thanks,

Ashish

 

Hi @tulasi8,

Please use the flow designer logic exactly as shown below. In your current flow, you are checking if the state is Closed Complete, but instead, your flow should wait until the state of all SCTasks is either Closed Complete or Closed Incomplete before proceeding.

Let me know if you need any help implementing this.

Screenshot 2025-07-11 at 12.20.59 PM.png

 

In Wait for condition , dont check enable timeout check box and also dont specify any time limit , so that it will wait till the state of sctasks are closed or not

 

 

Thanks regards

Badrinarayan

 

Ankur Bawiskar
Tera Patron
Tera Patron

@tulasi8 

you should have after update business rule on sc_task

Condition: Active [Changes to] False AND current.request_item.cat_item.name == 'Your Item'

Script:

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

    // Add your code here
    var taskRec = new GlideRecord('sc_task');
    taskRec.addActiveQuery();
    taskRec.addQuery('request_item', current.request_item);
    taskRec.setLimit(1);
    taskRec.query();
    if (!taskRec.hasNext()) {
        var ritm = current.request_item.getRefRecord();
        ritm.state = 3;
        ritm.update();
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar it's not working even updating the script in business rule.

 

Regards,

Tulasi.