Close RITM only if all tasks are closed

sbeginner
Kilo Guru

Hi All,

I have a workflow that creates a single task and other tasks team creates for approvals and stuff. The issue is, once the 

workflow created task gets Closed the WF moves to end activity and stage is completed even when other manual tasks are still open. I tried writing a Before/update After/update BR but is not helping. Can you please help?

1 ACCEPTED SOLUTION

Rana5
Tera Expert

Create a Wait for condition with following script:

 

var task = new GlideRecord("sc_task");
task.addEncodedQuery("stateNOT IN3,4^request_item=" + current.sys_id);
task.query();
var count = task.getRowCount();
if (count == 0)
answer = true;

 

You can put this inside a function as well. No need of any BR or additional field on RITM level.

 

Regards,

Rana

View solution in original post

13 REPLIES 13

Hi @Nayan Dhamane It is now not waiting on wait for condition activity but directly closing after first task is closed. Like it was happening earlier.

sbeginner_0-1669111613692.png

 

Hello @sbeginner ,

What is the conditioni n wait for condition, is the checkbox true or false.

Kindly let me know.
BR,
Nayan

If my answer solved your issue, please mark my answer as āœ…Correct & ļ‘Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

@Nayan Dhamane In wait for condition it is true in WF.

sbeginner_0-1669113862816.png

 

Community Alums
Not applicable

Where is the field All Tasks Closed located? If on RITM, how it is setting to true?

Community Alums
Not applicable

In the wait for condition activity, try like this:

 

//Query for all tasks to see if they are inactive
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('active', true);
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}