Find or Open Loop
The Find or Open Loop action looks for a loop of one loop type whose fields hold the values you give it. When no loop matches, it opens a new one. Two runs that look for the same values at the same time end up with one loop, not two.
When to Use This Action
Use this action when:
- An email arrives from a customer and you want the loop for that customer's email address, or a new loop if there is none yet
- You want one long-running process per order number, ticket number, or device, without creating duplicates
- You only want to check whether a loop exists (clear Open a loop when none matches) and continue based on the answer
If you already have the loop's ID, use the other loop actions, which take the ID directly.
Configuration
| Field | Description |
|---|---|
| Loop Type | The loop type to search. Required. It must belong to your account. Choose it from the list, or unlock the field and type its ID, its name, or a text expression that renders one of them. Names ignore case and must be unique among your loop types. |
| Match Fields | The indexed fields to search by and the values a loop must hold. Add at least one row. When the action opens a loop, it saves these values on it. |
| Open a loop when none matches | On by default. When cleared, the action only looks for a loop and does nothing when there is none. |
| Title | The title of a loop this action opens. Supports text expressions. |
| Initial Field Values | Values stored on a loop this action opens, in addition to the Match Fields values. A value here replaces a match value for the same field. |
| Initial Stage | The stage a new loop starts in. Choose it from the list, or unlock the field and type the stage's ID, its name (ignoring case), or a text expression that renders one of them. Leave empty for the first stage of the loop type. |
Choosing from a list or typing a value
Loop Type, Initial Stage, and the Field fields have a lock button next to them.
- Locked (the default): you choose from a list. The action remembers the choice by ID, so renaming a stage or field later does not break it.
- Unlocked: you type the ID, the name, or a text expression. The action looks for an ID first and then a name. Capitals do not matter for loop type or stage names. Field names must match exactly, including capitals. If two loop types share a name, use the ID or choose the type from the list.
Only saved stages and fields are listed. A stage or field you add while editing a loop type appears in the lists after you save the loop type. A stage or field list needs a locked Loop Type in this action. While Loop Type is unlocked or empty, type the name or ID instead.
Match Fields
Each row has a Field and a Value. A loop matches when it holds all of the values.
| Field | Description |
|---|---|
| Field | An indexed field of the loop type. The list shows only the indexed fields; if the loop type has none, mark a field as indexed in the loop type first. Choose it from the list, or unlock the field and type its name (the name used as loop.<name>, for example customer_email, not the display label; names are case-sensitive), its ID, or a text expression that renders one of them. A field that is not indexed is not allowed. Mark the field as indexed in the loop type first. |
| Value | The value the field must hold. Supports text expressions. It cannot be empty. |
Initial Field Values
Each row has a Field (chosen or typed the same way as in Match Fields) and a Value, and works like the field values of Update Loop Data. The title, initial field values, and initial stage only apply to a loop this action opens. A loop that is found is not changed.
The values you enter in Match Fields are saved on the new loop automatically, so you do not need to repeat them here. Rows here add more values. This is what lets the next run find the loop instead of opening a second one. If a row here uses the same field as a match row, the value in Initial Field Values is saved instead.
Returned Variables
If you configure the Store the results in Variable option for this action, the variable holds:
| Variable | Type | Description |
|---|---|---|
found | true/false | True when a loop that already existed matched. |
opened | true/false | True when this action opened a new loop. |
loop | object or empty | The loop. Empty when nothing matched and no loop was opened. |
The loop object has these values:
| Variable | Description |
|---|---|
loop.id | The ID of the loop. |
loop.open | True when the loop is open, false when it is closed. |
loop.title | The title of the loop. |
loop.stage.id | The ID of the loop's stage. |
loop.stage.name | The name of the loop's stage. |
loop.data | The loop's field values keyed by field name. Every field of the loop type is present, with an empty value where nothing is stored. |
For example, with the result variable found_loop, {{custom.found_loop.loop.id}} is the loop's ID and {{custom.found_loop.loop.data.customer_email}} is the customer's email address.
Notes
- Closed loops are found too, with
loop.openset to false. The action never reopens a loop. Checkloop.open, and use Reopen Loop if the loop should run again. - When several loops match, the oldest one is returned. The history of the run says that more than one matched.
- The action fails if a match field does not exist on the loop type, is not indexed, or has an empty value. The message names the field.
- The action fails if the same field appears twice in Match Fields, or twice in Initial Field Values when Open a loop when none matches is on. Remove the duplicate row.
- The action fails, and opens no loop, if a match value is not valid for its field (for example, text in a number field) when a loop would be opened.
- The action fails if a value in Initial Field Values is not valid for its field, or if Initial Stage is not a stage of the loop type.
- If another run is looking for or opening a loop with the same values and does not finish within a few seconds, the action fails with a message saying so. Run the action again.