Skip to Content

For Each

Process each item in an array data source sequentially. Use for batch updates, aggregations, and repeated operations over lists.

Overview

The For Each action iterates over an array and runs the same logic for every element.

Supported data sources:

  • Page data: Remove the row limit to return the full array
  • Select view: Enable multi-select to process chosen rows

To loop a fixed number of times, use the SEQUENCE formula to build an array of the desired length and use it as the data source.

Common scenarios:

  • Shopping cart total: Sum price × quantity across cart items
  • Batch updates: Apply the same change to multiple records
  • Aggregations: Count, sum, or categorize items
  • Data sync: Push multiple records to an external system

Configuration

Parameters

ParameterTypeRequiredDescription
Data sourceArrayYesPage data or select view (multi-select)
Per-item actionsActionsYesLogic to run for each element

Setup

Prepare the data source

Configure page data without a row limit, or enable multi-select on a select view.

Add the loop action

Add For Each at the appropriate trigger (e.g. on data request success) and select the array data source.

Configure per-item logic

In Per-item actions, use Item Data to access the current row.

Set up accumulator variables (optional)

For totals or counts, add page variables and update them inside the loop.

Output

  • Item Data: Access the current row via item data in per-item actions
  • No direct return value; results come from actions inside the loop

Notes

  • Page data: Remove row limits for full arrays
  • Select view: Enable multi-select
  • Performance: Large arrays may affect performance; consider batching
  • State: Page variable changes persist across iterations (suitable for accumulators)

Platform Support

  • Web
  • Native App

Examples

Shopping cart total

// 1. Page variable: total (Arbitrary Precision Decimal, default 0) // 2. Page data: cart_items (no row limit) // 3. For Each: Data source: cart_items Per-item actions: - Set page variable "total" = total + (item data.quantity * item data.unit_price) // Calculation: // Start: total = 0 // Item 1: qty 2, price 100 → total = 200 // Item 2: qty 3, price 200 → total = 800

Batch status update

// Mark selected orders as "Shipped" Data source: order_select_view.selected_items Per-item actions: - Update data "orders" - Filter: id = item data.id - Set: status = "Shipped" - Show toast: "Order {item data.order_number} updated"

Category count

// Count products by type // Page variables: electronics_count, apparel_count, food_count Data source: product_list Per-item actions: - Conditional: - If item data.type == "Electronics": electronics_count + 1 - If item data.type == "Apparel": apparel_count + 1 - If item data.type == "Food": food_count + 1

Batch export

// Export selected users to an external API Data source: user_select_view.selected_items Per-item actions: - Call API: - URL: "https://api.external.com/users" - Method: POST - Body: { name: item data.name, email: item data.email, phone: item data.phone } - On success: Show toast "Exported {item data.name}" - On failure: Show toast "Failed to export {item data.name}"
Last updated on