"Wait for Child Tasks to Close" Activity in Flow Designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2019 08:09 AM
Has anyone developed a Flow Designer activity for the Service Catalog that mirrors the old "Wait for Child Tasks to close" Workflow activity? I use this in a lot of my catalog item workflows to be sure to allow any manually created catalog tasks are closed before ending the workflow.
This does not appear to be an out of box activity for flow designer.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 03:54 PM
So hopefully this will answer some questions. I have the same requirement where I need to wait for all child tasks to close before proceeding. To achieve this in flow designer, you can 'look up the records' and run a 'for each' logic and set a wait for condition. The downside to this is that it doesn't accommodate manually created tasks, so once your initial set of tasks in your 'lookup records' are complete, it will proceed to negate the fact you have other tasks. That's a problem, right?
So here are my steps that mitigate that problem using Flow Design + Workflow:
1. Create a new workflow, yes, WORKFLOW
- Name: Flow Designer - Wait for Child Task Completion
- Table: Global
- Description: A simple workflow that waits for the completion of wall child tasks before proceeding.
2. Add a Wait for condition
- In the condition script, use the following snippet:
// Using .getRowCount()
answer = checkTaskComplete();
/**
* Runs a GlideRecord on sc_task for tasks that are not closed.
* @return {Boolean} True or False
*/
function checkTaskComplete() {
var gr = new GlideRecord("sc_task");
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state', '!=', '3');
gr.query();
if (gr.getRowCount() >= 1) {
return false;
} else {
return true;
}
}
// Using GlideAggregate
answer = checkTaskComplete();
/**
* Runs a GlideAggregate on sc_task for tasks that are not closed.
* @return {Boolean} True or False
*/
function checkTaskComplete() {
var count = 0,
gr = new GlideAggregate('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state', '!=', '3');
gr.addAggregate('COUNT');
gr.query();
if (gr.next())
count = gr.getAggregate("COUNT");
if(count >= 1)
return false;
return true;
}
Note: modify it as you see fit.
3. Drag your lines accordingly and PUBLISH your workflow. This step is important because if you don't publish it, it will now show up as a selectable option.
4. Go back to your flow designer and your flow.
5. In your flow or subflow add a Flow Logic > Call a Workflow
- Select a Workflow: Flow Designer - Wait for Child Task Completion
- Wait: Checked
- Current: Input->Request Item
6. Do whatever steps you have afterward, run several tests, and you're done.
Here is what I did to verify the flow worked. Create a manual task during the Call a Workflow step, close the generated tasks first, and observe the flow. It will not proceed and then close the manually created tasks, and it will proceed forward.
Here's a thought, if you don't want to call a workflow each time your flow executes, do the "Look Up Records" action and add a "for each" and set a "wait for condition" beforehand. Then have another "Look Up Records" actions, and if the count is greater than 0, then call the workflow afterward. The Workflow will be treated as a catch-all type step.
Anyways, I hope this helps those out looking for a solution when dealing with child tasks.
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 12:55 PM
Hello Dave.
- I assume you dont use the full script, just use either the '// Using .getRowCount()' method, or the '// Using GlideAggregate' method.
- I created a workflow as described see image 1
- I created a condition in the workflow using this script - see image 2
- I added a gs.log to the script - the count is always returning 0
- I added the workflow in the flow designer - see image 3
- The flow workflow executes, but always ends.
- The workflow execution is in image 4
- I tested by adding a task before the workflow execution, and while the first task was open.
- In step 5: wheredo you put the Current: Input->Request Item ?
5. In your flow or subflow add a Flow Logic > Call a Workflow
Select a Workflow: Flow Designer - Wait for Child Task Completion
Wait: Checked
Current: Input->Request Item
Any suggestion greatly appreciated. Thanks, Mark S

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2021 11:50 AM
"Current" will not be available for selection if you call a workflow on the "Global" table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 02:34 AM
Hi Dave,
I appreciate that this article is a bit old now but I wanted to check whether you know if the 'wait' option (in flow designer) constitutes a 'loop' as far as the 'Maximum iterations per loop' system property (below) is concerned.
I've just added the actions recommended in the 'top answer' above as there will be no manual tasks created which you were having to cater for. But I'm now wondering if the 1000 limit may come into affect - I'm busy testing and still waiting to see if any of the flows error due to this.
Thanks,
Keiron.
Maximum iterations per loop
sn_flow_designer.max_iterations |
The maximum amount of iterations that a loop will run in Flow Designer. A loop will error out if it iterates beyond this value, preventing infinite loops.
Note: Changing this value will not effect flows that are already in progress.
|