For Each Stage

The For Each stage in AiFlo is used to loop through a list of records, items, or values and perform specific actions on each item individually. It’s like saying, “For every item in this list, run these stages.”

This is useful when you have multiple similar records to process — for example:

  • Sending an email to each contact in a CRM list.

  • Updating the status of all pending orders.

  • Performing AI analysis on multiple uploaded documents.

When to Use

Use For Each when:

  • You want to repeat certain workflow steps for every item in a collection.

  • You have a stage that returns multiple records (e.g., Get Records).

  • You want to process each record independently but in the same workflow run.

For Each Stage – Configuration

Step 1. Select Repository

Choose the repository you want to loop over. Example: Candidate

Once selected:

  • All fields from the repository will appear in Select Field dropdown.

  • All previous workflow variables will also be available for filtering and comparison.

Step 2 – Define Filter Conditions

The Condition Builder allows you to filter which records will be processed.

Condition Builder Components:

  1. Logical Operator

    • AND – All conditions must be true.

    • OR – At least one condition must be true.

  2. Select Field

    • Shows all repository fields and previous workflow variables.

  3. Select Condition

    • Available options depend on field type:

Field Type

Supported Conditions

Calculate / Date / Number / Decimal

Equals, Not Equal, Greater Than, Less Than, Greater Than Equal, Less Than Equal

Checkbox

Equals, Not Equal

Email, Select, User or Group, Single Line, Lookup, Variable, Multiselect

Equals, Not Equal, Contains

Steps 3- Select Value

  • Options depend on field type

Field Behavior by Type:

A. Supports Custom & Variable Value

  • Field Types:

    • Single Line

    • Multi Line

    • Email

    • Checkbox

    • Lookup

    • Multiselect

    • Select

    • Attachment

    • User or Group

    • Hyperlink

    • Location

Value Options:

  • Custom: Manual input (e.g., Name → Custom → "Raaghav").

  • Variable:

  • Workflow variable reference (e.g., ${Variable:CandidateName}).

  • For record/records type variables, you can reference a specific field:

${Variable:VariableName:FieldName}

B. Supports Custom, Calculated & Variable Value

  • Field Types:

    • Decimal

    • Number

    • Date

Value Options:

  • Custom: Manual numeric/date input (e.g., 200.5, 2025-01-01).

  • Calculated: Use an expression or formula (e.g., <TODAY><PLUS>2).

Variable: Workflow variable reference (${Variable:VariableName},

e.g. ${Variable:Candidate_Name}).

Step 5 – Add Nested Stages

  • The stages placed inside the For Each will run for each matching record.

  • Inside For Each, all General stages and AI stages can be used, and they will execute for each record in the loop.

  • Example:

    • Update Record

    • Send Email

    • AI Stage

    • Add Record

Execution Flow

  1. Retrieve matching records from the repository.

  2. For each record:

    • Run all nested stages sequentially

  3. Continue until all records are processed.

Real-Time Example

Scenario: Send a screening email to all candidates applying for "Software Engineer" who have at least 3 years of experience.

For Each Stage Setup:

  • Repository: Candidate

  • Filter Conditions:

    1. Position Applied → Equals → Custom → "Software Engineer"

    2. Years of Experience → Greater Than Equal → Custom → 3

Inside For Each:

Send Email

    • To: ${candidate.Email}

    • Subject: "Screening Interview Invitation"

    • Body:

Hi ${candidate.Name},

Thank you for applying for the Software Engineer position.

We’d like to invite you for a screening interview.

Please reply with your availability.

Regards,

HR Team

Result:

Only matching candidates receive the email.

Last updated