---
title: Set Variable
description: Remember a named value for the rest of the current run
---

Remember a named value for the rest of this run, so any later node can read it as `{{ $run.name }}`.

## What it does

Set Variable stores a value under a name. Any node that runs after it can read the value with `{{ $run.name }}` in any field, with no edge to this node. That lets you carry a value to a node far away on the canvas, or build up a total or a list across the passes of a [Loop](/nodes/builtin/flow/loop/).

The **Operation** decides what happens to the variable:

* **Set**: store the **Value**, replacing what was there.
* **Add to number**: add the **Value** to the number already stored. A variable that is not set yet starts at 0, so you don't need to set it first.
* **Append to list**: add the **Value** to the end of a list. A variable that is not set yet starts as an empty list.
* **Delete**: forget the variable.

Variables last for **one run** and are gone when it ends. To remember something between runs, use [Data Store](/nodes/builtin/core/datastore/).

## When to use it

* Hand a value (a page cursor, a user name) to a step much further on without wiring it through every node in between.
* Count items or add up amounts over a Loop.
* Collect results from each pass of a Loop into one list.

## Inputs and settings

* **Name** may contain letters, digits, `_` and `$`, and must not start with a digit, for example `cursor` or `total_price`.
* **Value** is usually an expression such as `{{ $input.nextPage }}`. For **Add to number** it must be a number (or text that is a number, like `5`).

## Outputs

With **Pass The Item Through** on (the default), the incoming item goes out unchanged, so you can drop Set Variable in the middle of a chain. With it off, the item is replaced by a summary: `name`, `value` (what the variable now holds) and `operation`.

## Dependencies and credentials

None. This node needs no connection and has no slots for other nodes.

## Example workflow

Count the links on a page that point to PDFs:

1. [Get All Link](/nodes/extension/getalllinks/) with **Output field name** `links` reads the links of the open page.
2. [Split Out](/nodes/builtin/datatransformation/splitout/) with **Field To Split Out** `links` makes one item per link.
3. [Filter](/nodes/builtin/flow/filter/) keeps items where `{{ $input.links }}` (**String**) **Ends With** `.pdf`.
4. Set Variable with **Operation** **Add to number**, **Name** `pdfCount`, **Value** `1`. It runs once per kept link.
5. A later [Show Notification](/nodes/extension/shownotification/) shows `Found {{ $run.pdfCount }} PDFs`.

## Common issues

* **"Variable "x" has not been set at this point in the run."** A node read `{{ $run.x }}` before Set Variable ran. Only nodes downstream of Set Variable are sure to run after it; a node on a parallel branch may run first. Connect Set Variable upstream of the reader. The canvas also warns you when a read may come before the write.
* **"Variables only exist while a workflow is running."** You ran the node on its own. Run the whole workflow.
* **"... cannot be used as a variable name."** Use only letters, digits, `_` and `$`, not starting with a digit.
* **"Cannot append to "x" because it holds ..., not a list."** The variable was set to something else earlier. Use a new name, or **Delete** it first.
* **"The amount to add is not a number."** With **Add to number**, the **Value** must be a number.

## Related nodes

* [Get Variable](/nodes/builtin/flow/getvariable/): turn a stored value back into items.
* [Loop](/nodes/builtin/flow/loop/): repeat steps while updating a variable.
* [Data Store](/nodes/builtin/core/datastore/): remember values between runs.
* [Expressions](/concepts/data/data-mapping/data-mapping-expressions/): how `$run` and other expressions work.