When - Workflow Toolbox

The When toolbox item is designed to work in tandem with the Each toolbox item. It instructs the workflow to continue only when either all or a fixed amount of the subprocesses created by the Each toolbox item have been completed.

Common Uses

Taking the example used in the Each toolbox item article, that workflow created a telephone call task for all witnesses. If we added another step and used the When toolbox item, this could be configured to continue only when all of the subprocesses (tasks in this instance) or when a fixed amount of these have been completed.

Pre-requisites

  • Each toolbox item - As above, you will require a step containing an Each toolbox item before using the When toolbox item.
  • Step - To utilise this toolbox item, you will need to have a step on your canvas into which to drag it.

Configuring When

  1. Click on the toolbox tab of your workflow canvas.
  2. Select the When option and drag it onto the step where you wish to place it.
  3. Click on the When item you have dragged onto the canvas to add in the configuration.
  4. Enter the configuration for the toolbox item.
Wait for all This configures whether you want this only to continue once all subprocesses have completed.
Wait for

This is only visible if you selected 'No' to Wait for all and it allows you to define the amount of subprocesses that must complete before this continues.

See the note below.

Output count to variable This will output the number of subprocesses that were completed at the time of the When item triggering.

"Wait for" accepts a variable

In workflows that iterate over a dynamic collection using a for-each loop, each item may go through multiple logic steps before joining at a When block. This can cause race conditions, where not all triggers are set up in time—making Wait for all unreliable.

Using a static number also doesn't work if the number of items varies (e.g. 0 or 100). To handle this, the When block can accept a variable as the Wait for count. This allows you to pass in the actual number of items from the query, avoiding the need to break logic into sub-processes.