packages/twenty-docs/user-guide/workflows/capabilities/use-iterator.mdx
Iterator lets you loop through an array of records and perform actions on each one. It's essential for workflows that need to process multiple records returned by Search Records or received via webhooks.
| Scenario | Example |
|---|---|
| Process search results | Send email to each person found |
| Handle webhook arrays | Create records for each item in order |
| Bulk updates | Update multiple records with calculated values |
| Notifications | Alert multiple people about an event |
Iterator expects an array as input. It then:
Goal: Find all contacts in a specific company and send each one a personalized email.
{{searchRecords.length}} is greater than 0{{searchRecords}}Actions placed after Iterator run for each item:
{{iterator.currentItem.email}}{{iterator.currentItem.firstName}}!If Search Records returns 5 people, the Iterator:
Inside Iterator, use {{iterator.currentItem}} to access the current record:
| Variable | Description |
|---|---|
{{iterator.currentItem}} | The entire current record object |
{{iterator.currentItem.id}} | Record ID |
{{iterator.currentItem.email}} | Email field |
{{iterator.currentItem.company.name}} | Related company name |
{{iterator.index}} | Current position in array (0-based) |
Goal: Mark all overdue tasks as "Late"
1. Search Records (Tasks, Due Date < Today, Status ≠ Completed)
2. Filter (length > 0)
3. Iterator (searchRecords)
└── Update Record
- Object: Tasks
- Record: {{iterator.currentItem.id}}
- Status: Late
Goal: Webhook receives order with multiple items, create a record for each
1. Webhook Trigger (receives items array)
2. Filter (items.length > 0)
3. Iterator (trigger.body.items)
└── Create Record
- Object: Order Items
- Name: {{iterator.currentItem.name}}
- Quantity: {{iterator.currentItem.qty}}
- Related Order: {{trigger.body.orderId}}
Goal: Only send email to contacts with valid emails
1. Search Records (People)
2. Iterator (searchRecords)
└── Filter (currentItem.email is not empty)
└── Send Email
- To: {{iterator.currentItem.email}}
Cause: You passed a single record instead of an array.
Fix: Make sure you're passing the result of Search Records or an array field, not a single record.
✅ Correct: {{searchRecords}}
❌ Wrong: {{searchRecords[0]}}
Cause: The array is empty.
Fix: Add a Filter before Iterator to check array length:
Filter: {{searchRecords.length}} > 0
Cause: Search Records returned more records than expected.
Fix: