# Set Variable



The **Set Variable** block allows you to store data that needs to persist across different flow executions. Unlike temporary variables, storage variables are saved in the project's database and can be accessed by any flow in your project at any time.

Configuration [#configuration]

| Field                  | Required | Description                                                                                                                                                            |
| :--------------------- | :------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Variable**           |     ✅    | Select the persistent variable to modify. You can create these in your project's Data Storage settings. Valid types include `string`, `number`, `array`, and `object`. |
| **Variable Operation** |     ✅    | The action to perform on the selected variable. Options vary based on the variable's type (e.g., `Set Value` for strings, `Push to End` for arrays).                   |
| **String Value**       |     ✅    | The text content to store in the variable (visible when a `string` variable and `Set Value` operation are selected).                                                   |
| **Number Value**       |     ✅    | The numerical value to store (visible when a `number` variable and `Set Value` operation are selected).                                                                |
| **Array Value**        |     ✅    | The item(s) to add or remove from an array (visible for `array` operations like `Push to End` or `Remove Value`).                                                      |
| **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 (visible for `object` operations). Supports dot notation (e.g., `user.profile.name`).                             |
| **Object Path**        |     ✅    | The path(s) to the properties you want to remove from an object (visible for the `Delete Value` operation).                                                            |

<Callout type="info" title="Reading Persistent Variables">
  You can read the value of a persistent variable anywhere in your flows using the syntax: `{variable_name}`. For temporary, non-persisted data, see the [Create Temporary Variable](create-temporary-variable.mdx) block.
</Callout>

<Callout type="warning" title="Storage Limits">
  Persistent variables have size limits to ensure performance. Large arrays or deep objects may trigger errors if they exceed project settings (typically 2MB).
</Callout>

Error Handling [#error-handling]

* `MISSING_VARIABLE` — Triggered when no variable is selected.
* `VARIABLE_NOT_FOUND` — Triggered if the selected variable is missing from the project storage.
* `INVALID_OPERATION` — Triggered when the operation doesn't match the variable type.
* `STORAGE_ERROR` — Triggered if the database fails to update.
* `INVALID_INDEX` — Triggered when an array index is out of bounds.
* `STRING_TOO_LONG` — Triggered if the string exceeds the maximum character limit.
* `NUMBER_OUT_OF_RANGE` — Triggered if the number is outside the allowed range.
* `ARRAY_TOO_LARGE` — Triggered if the array size exceeds the maximum MB limit.
* `OBJECT_TOO_LARGE` — Triggered if the object size exceeds the maximum MB limit.
* `OBJECT_TOO_DEEP` — Triggered if the object nesting exceeds the maximum depth.
* `VAL_INVALID` — Triggered when the provided value is incompatible with the expected format.
* `RUNTIME_ERROR` — Triggered if an unexpected error occurs during execution.

Example: Updating User Profile [#example-updating-user-profile]

Imagine you want to track the "Last Login" time for a user in your persistent storage.

1. **Prerequisite**: Create a variable named `user_data` of type `object` in your project's Data Storage.
2. **Add a Set Variable Block**:
   * **Variable**: `user_data`
   * **Variable Operation**: `Set Value`
   * **Object**:
     * Key: `last_login`
     * Value: `{request.headers.date}` (using the date from the incoming request).
3. **Execution**: When this block runs, it will update the `user_data` object in the database.
4. **Result**: Subsequent flows can access this value using `{user_data.last_login}`.

Related Blocks [#related-blocks]

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

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