For
Function: For
The "For" function allows you to repeat a specific action a set number of times. It's like telling the platform, "Do this task, then do it again, and keep doing it until a certain count is reached." This is incredibly useful for automating repetitive tasks, such as processing a list of items, generating multiple records, or performing calculations in a sequence.
Input
- Start (Number): This is the initial value of a counter. The action will begin executing when the counter is at this value.
- End (Number): This is the value at which the loop stops. The action will continue to execute as long as the counter is less than this value.
- Increment (Number): This determines how much the counter increases after each time the action is performed. For example, an increment of 1 means the counter goes up by one each time.
- Action (Action): This is the specific action you want to repeat. You select an existing action from your platform's library.
- Action parameters (Action Parameters): These are any additional inputs or settings required by the
Actionyou've chosen to repeat. The specific parameters available here will change depending on theActionyou select. You can also use a special variable calledINDEXwithin these parameters, which will automatically update with the current count of the loop for each repetition.
Output
- Action outputs (Action Outputs): This collects all the results generated by each execution of the repeated
Action. If the repeated action produces an output, this function will gather all those individual outputs into a list, allowing you to use them later in your application.
Execution Flow
Real-Life Examples
Example 1: Generating Multiple Invoice Items
- Scenario: You need to create 5 identical line items for a new invoice, perhaps for a standard service package.
- Inputs:
- Start:
1 - End:
6(The loop will run forINDEXvalues 1, 2, 3, 4, 5) - Increment:
1 - Action:
Create Invoice Line Item(an existing action that adds a line item to an invoice) - Action parameters:
Invoice ID:\{\{Current Invoice.ID\}\}Item Name:"Standard Service"Quantity:1Price:100.00Line Number:\{\{INDEX\}\}(This uses the loop counter to assign a unique line number to each item)
- Start:
- Result: Five new line items are added to the current invoice. Each line item is named "Standard Service", has a quantity of 1, a price of 100.00, and a unique line number from 1 to 5. The
Action outputswould contain the details (e.g., IDs) of the five newly created line items.
Example 2: Sending Reminder Emails to a Segment of Users
- Scenario: You want to send a series of 3 personalized reminder emails to a specific group of users, with each email having a slightly different subject line (e.g., "Reminder 1", "Reminder 2", "Final Reminder").
- Inputs:
- Start:
1 - End:
4(The loop will run forINDEXvalues 1, 2, 3) - Increment:
1 - Action:
Send Email(an existing action that sends an email to a specified recipient) - Action parameters:
Recipient Email:\{\{User.Email\}\}(assuming this action is part of a larger flow iterating through users)Subject:"Reminder \{\{INDEX\}\} for your upcoming appointment"Body:"This is reminder number \{\{INDEX\}\} for your appointment. Please confirm your attendance."
- Start:
- Result: Three reminder emails are sent to the user. The first email has "Reminder 1" in the subject, the second "Reminder 2", and the third "Reminder 3". The
Action outputswould contain the status of each email sent (e.g., "Sent", "Failed").
Example 3: Updating Inventory Levels for Multiple Products
- Scenario: You have a list of 10 products that just arrived in a shipment, and you need to increase their stock level by 5 units each.
- Inputs:
- Start:
1 - End:
11(The loop will run forINDEXvalues 1 to 10) - Increment:
1 - Action:
Update Product Stock(an existing action that updates the stock level for a given product) - Action parameters:
Product ID:\{\{Product List.Item[INDEX-1].ID\}\}(assuming you have a list of products and you're using theINDEXto pick each one.INDEX-1is used if the list is 0-indexed)Quantity Change:5Operation:"Add"
- Start:
- Result: The stock level for 10 different products is increased by 5 units each. The
Action outputswould contain the updated stock levels or confirmation messages for each product.