# Set Temporary Variable



The **Set Temporary Variable** block allows you to update the value of a temporary variable that was previously created in your flow. Use this block for logic like incrementing counters, adding items to a temporary list, or updating a status flag during flow execution.

Configuration [#configuration]

| Field                  | Required | Description                                                                                                                                                                       |
| :--------------------- | :------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Variable**           |     ✅    | Select the temporary variable to set or update. You must first create the variable using a [Create Temporary Variable](create-temporary-variable.mdx) block earlier in your flow. |
| **Variable Operation** |     ✅    | The action to perform on the selected variable. Options vary based on the variable's type (e.g., `Push to Front` for arrays, `Set Value` for numbers).                            |
| **String Value**       |     ✅    | The text content to store in the variable (visible for `string` operations).                                                                                                      |
| **Number Value**       |     ✅    | The numerical value to store (visible for `number` operations).                                                                                                                   |
| **Array Value**        |     ✅    | The item(s) to add or remove from an array (visible for `array` operations).                                                                                                      |
| **Array Index**        |     ✅    | The zero-based position of the item to remove (visible for the `Remove Value at Position` operation).                                                                             |
| **Object**             |     ✅    | The key-value pairs to set within an object variable. Supports nested paths using dot notation.                                                                                   |
| **Object Path**        |     ✅    | The path(s) to the properties you want to remove from an object.                                                                                                                  |

<Callout type="warning" title="Missing Initialization">
  If you attempt to use this block on a variable that hasn't been initialized by a [Create Temporary Variable](create-temporary-variable.mdx) block, the flow will trigger a `VARIABLE_NOT_INITIALIZED` error.
</Callout>

Error Handling [#error-handling]

* `MISSING_VARIABLE` — Triggered when no variable is selected.
* `VARIABLE_NOT_FOUND` — Triggered if the variable definition cannot be found.
* `VARIABLE_NOT_INITIALIZED` — Triggered if the selected variable has not been created yet in the current flow.
* `INVALID_OPERATION` — Triggered when the operation is incompatible with the variable's data type.
* `INVALID_INDEX` — Triggered when an array index is invalid or out of bounds.
* `STRING_TOO_LONG` — Triggered if the string exceeds the 2,000-character limit.
* `NUMBER_OUT_OF_RANGE` — Triggered if the number exceeds the allowed range (+/- 9^50).
* `ARRAY_TOO_LARGE` — Triggered if the array size exceeds 2MB.
* `OBJECT_TOO_LARGE` — Triggered if the object size exceeds 2MB.
* `VAL_INVALID` — Triggered when the provided value format is incorrect.
* `RUNTIME_ERROR` — Triggered if an unexpected error occurs during execution.

Example: Tracking Item Counts [#example-tracking-item-counts]

Suppose you are iterating through a list of orders and want to count how many are marked as "urgent".

1. **Step 1**: Use a **Create Temporary Variable** block at the start of your flow to initialize `urgent_count` to `0`.
2. **Step 2**: Inside your loop, add a **Set Temporary Variable** block:
   * **Variable**: `urgent_count`
   * **Variable Operation**: `Set Value`
   * **Number Value**: `{urgent_count} + 1` (Note: Ensure your logic evaluates the incremented value).
3. **Outcome**: After the loop, the temporary variable `{urgent_count}` will hold the total number of urgent orders, which you can then use in a final notification block.

Related Blocks [#related-blocks]

<Cards>
  <Card title="Create Temporary Variable" href="/docs/blocks/variable-blocks/create-temporary-variable" />

  <Card title="Set Variable (Persistent)" href="/docs/blocks/variable-blocks/set-variable" />
</Cards>
