# Store values in variables

Keep a value in one place for the whole run, so several steps can read it and update it.

Source: https://support.rework.com/article/store-values-in-variables

Tokens reach back to one specific step, and that covers most cases. Sometimes, though, a value has to travel further: a score several branches need, a counter that grows as a loop goes round, a setting the whole automation should share. That's exactly what **automation variables** are for.

## Step 1: Declare the variables

- Open the automation and click **More** > **Manage variables**.
  

![The More menu with Manage variables](https://storage.googleapis.com/reworkv3-public/success/260923/XViNB4q8KRbvM5BzgZELgoYD9653JtIZDyj4LW6quFqQnLnDVUnT10LyHMzaBAer/img.bf1WTEpBsWy20j2sT0eXbxx0WLMDVfOJeSH8qjgWvunDq73htiKSU2B8YDUu9exa.png)

- Each row is one variable: a **Name**, an optional **Default value** used before anything sets it, and a **Description** so the next person knows what it holds.
  
- Click **Add variable** for another row, the bin icon to remove one, then **Save**.
  

![The Automation variables dialog with one variable](https://storage.googleapis.com/reworkv3-public/success/260923/5uxvVRgbi81WULBQMUhN1oGn5yeDQobHwAq2s6InPeVHsXabjHERN8DT37TFVmTc/img.I1OWYPZLcTZScN6zcFi7CwXSXdpiQQyhvdPQs2EeIr907BYgDtwVANpwyxPP3LSX.png)

## Step 2: Set a variable in the flow

Add a **Set variable** step where the value becomes known, for example right after the trigger.

- **name**: the variable to write to.
  
- **value**: what to store. Insert a token to take it from an earlier step, for example the score that arrived with the webhook.
  
- **create\_if\_not\_exists**: **Yes** creates the variable if it was never declared. **No** fails instead, which is handy when you'd rather catch a typo than silently create a second variable.
  
- **description**: what this value means.
  

![The Set variable step with its name, value and options](https://storage.googleapis.com/reworkv3-public/success/260923/MEgckZzYmvWrz7fgxeRmyafIBTCVLGRcjGis2MiGk7YpJ38D5uqHNiPRLOpH7rAT/img.M0RL9QUu2lo6RcGFs6jwZEuyySUE2YfUN7NSMAJ2Tie1B2osP8q3bJkwtr9M7UVq.png)

## Step 3: Read it further down

Anywhere below, reference the variable as `{{var.<name>}}`, for example `{{var.lead_score}}`. Two more steps come with it:

| Step | Does |
| --- | --- |
| **Set variable** | Stores a value |
| **Get variable** | Reads a variable into the step's own output |
| **Increment variable** | Adds to, or subtracts from, a number in one atomic step, which is what you want for counters inside a loop |

![The three variable steps in the step picker](https://storage.googleapis.com/reworkv3-public/success/260923/4ATDEUIoFeSVknAW0b6pILRnbUj3dIZ79f57VPwZ8g8MqPldaxlChjZa1wVPA1fr/img.ET7i8bgwk4ksLJ5GI4m9EguwMUEEwGnhY5VGtWcUNYj6wb8JdWns6dKCbjdXTt8m.png)

## When to use a variable instead of a token

| Use | When |
| --- | --- |
| A token, `{{step.field}}` | The value comes from one step and is used just below it |
| A variable, `{{var.name}}` | The value is set on one branch and read on another, counted up in a loop, or used in many places |

💡 Variables belong to one automation and hold their value for the length of a run. See [Pass data between steps](https://support.rework.com/article/pass-data-between-steps) for tokens and the Data Selector.
