- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2023 01:00 PM - edited ‎10-25-2023 01:07 PM
Need to loop through a number of records but want all records to be processed at one time. Do not need to wait for one record to be processed before processing the next. The step after the loop don't want to process until all the records in the Array have been processed.
Pseudo-code example
1 For Each Item in (Array)
2 Execute Sub-flow with Wait For Completion Uncheck
3 End of Loop
4 Lookup record
- Will the flow go to Step 4 before all the records have been processed in the loop? even if wait for completion is unchecked?
- Is there a way to make sure Step 4 is not executed until all the records in the loop have been processed?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 02:25 PM
Will the flow go to Step 4 before all the records have been processed in the loop? even if wait for completion is unchecked?
Will go to Step 4 prior to completing all work because Wait for completion is unchecked.
Is there a way to make sure Step 4 is not executed until all the records in the loop have been processed?
Only if
- beforehand a flag is set on records to be processed indicating that processing is pending
- sub-flows when completed would mark the particular record as having been processed by updating the flag
- setting up a Do the following until Flow Logic that looked up any of the records to be processed and set a watch on any found record until the flag is set to "processed" - until no records to be processed are found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2023 03:55 PM
Hi, javascript is a single threaded language, each step/function in code is completed before moving to the next step.
So code will loop through the array, then for each element in the array action any functionality within the loop, then move to step 4 only once the loop is complete.
But this behavior may differ for sub-flow/workflow as these components may run asynchronously to the parent that is triggering them.
For workflow the doc's indicate
'Wait for completion' when selected, the workflow activity waits for the task to complete before continuing. If cleared, the task is created but the workflow proceeds.
Create Task workflow activity (servicenow.com)
For flow this behavior depends on the trigger type eg
Dynamic flows flow logic (servicenow.com)
Call a workflow flow logic (servicenow.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 12:44 PM
I don't feel this answered my question. I understand how this will work in javascript, trying to understand how this works in Flows (Flow Designer)
As you stated from the documentation...
'Wait for completion' when selected, the workflow activity waits for the task to complete before continuing. If cleared, the task is created but the workflow proceeds.
Does this mean that the Loop could be done, but the items/tasks within the loop could still be processing? Which means that the step 4 after the loop could be processed before all the tasks within the loop have processed?
Assuming that is true, is there any way to tell when all the tasks in the loop have completed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 01:22 PM
'Does this mean that the Loop could be done'
Yes, in this context the underpinning tasks would be created, but the workflow is not waiting for them to be closed before proceeding to it's next activity.
'Assuming that is true, is there any way to tell when all the tasks in the loop have completed?'
I think inter-changing terminology might be causing some confusion.
task = a record related to tracking user action eg, Incident, request etc.
Do you mean 'activities' within a flow\workflow? if yes then when all activities are completed we would expect the flow\workflow to end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 02:25 PM
Will the flow go to Step 4 before all the records have been processed in the loop? even if wait for completion is unchecked?
Will go to Step 4 prior to completing all work because Wait for completion is unchecked.
Is there a way to make sure Step 4 is not executed until all the records in the loop have been processed?
Only if
- beforehand a flag is set on records to be processed indicating that processing is pending
- sub-flows when completed would mark the particular record as having been processed by updating the flag
- setting up a Do the following until Flow Logic that looked up any of the records to be processed and set a watch on any found record until the flag is set to "processed" - until no records to be processed are found.