ForEach Activity

Purpose: Iterate over a set of values. This activity executes a body activity for each item in a collection.

Input Properties

Items

The collection of values to iterate over.

Type: ICollection<object>

Default: Empty collection

Required: Yes

Note: Can be a literal collection, expression that returns a collection, or variable reference. Supports arrays, lists, and other enumerable collections.

Output Properties

CurrentValue

The current item being iterated in the loop. Assign this to a variable to use the current item in the loop body.

Type: object

Note: This output is automatically set to the current item on each iteration. Connect it to a variable to access the current value.

Port Properties

Body

The activity to execute for each item in the collection.

Type: IActivity

Note: Connect the activity or sequence of activities you want to execute for each item. The CurrentValue is available in this body.

Usage Example

Scenario: Process each item in a list of file names

Configuration:
- Items: "{{ Variables.FileNames }}" (a list like ["file1.txt", "file2.txt", "file3.txt"])
- CurrentValue: Assign to variable "CurrentFile"
- Body: Connect to activities that process the CurrentFile

Result:
- The Body activity executes once for each file name
- CurrentValue contains the current file name in each iteration
- Loop completes after processing all items

Important Notes

  • The loop executes sequentially - one item at a time
  • If the Items collection is empty, the Body activity never executes
  • Use the Break activity inside the loop body to exit early
  • The CurrentValue output is automatically updated on each iteration
  • For parallel execution, use ParallelForEach instead
  • Two variables are automatically available in the loop body: CurrentIndex (0-based) and CurrentValue
  • For strongly-typed collections, use ForEach<T> for better type safety

Related Activities