For the complete documentation index, see llms.txt. This page is also available as Markdown.

Foreach

The Foreach action node loops over objects in a data source and runs a block of action nodes for each object.

Usage

This action node is used to run a block of other action nodes repeatedly. The block will be run once for each object in the data source according to the object selection. On each iteration, the current object becomes the object in context.

Good to know

If you want to update or delete a selection of objects use the Update object or Delete objects action nodes.

Example

Your app has a data source containing all projects. You'd like to iterate over active projects to calculate resource utilization.

Use Foreach to loop over a filtered selection of projects with a filter Project.State EQUALS Active to only iterate over active projects.

Showroom

Showroom: Foreach example, with its setup in Appfarm Create (register for access).

Working with schemas

ForEach can iterate over an action variable or action param of type schema, provided the schema is an array. On each iteration, the current element becomes available as the object in context.

A single ForEach node descends one array level only. To iterate a nested array — for example, to loop over each Address on each Company — use two ForEach nodes: the outer node iterates the Company array, and an inner node iterates the Address array on each company.

Good to know Array-of-arrays schemas are not supported. If you need to represent a nested list, wrap the inner array in an object. For example, instead of an array of arrays of strings, define an array of objects where each object contains an array of strings.

Properties

Property
Description

Data source

Select a multi-cardinality data source containing the objects to iterate over. You may also select a multi-reference property (an Object Class Property with Cardinality Many), and iterate over the referenced objects. A multi-enum property can be iterated in the same way.

Selection

Define the objects to iterate over.

Not shown when Data source is a multi-reference or multi-enum property. All its values are iterated.

Filter

Available when Selection is Filtered selection. Define the filter to apply to the data source.

Execution mode

Sequential: The default. Iterations run one at a time, in order. Use this mode in most cases. Parallel: All iterations start at once and run at the same time. Within each iteration, the action nodes still run in sequence. If any iteration fails with an unhandled exception, the whole loop fails. Use this mode to speed up loops where iterations are independent, for example when each iteration calls an external service. Exit Loop and Next Iteration only end their own iteration and don't affect the others.

Iterator parameters

The action nodes inside the loop can use these built-in values:

Parameter
Description

Index in Iteration

Integer. The iteration index, starting at 0.

Is First Iteration

Boolean. True in the first iteration, otherwise false.

Is Last Iteration

Boolean. True in the last iteration, otherwise false.

Last updated

Was this helpful?