knoten / builtin / flow
Set Variable
Remember a named value for the rest of the current run
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Remember a named value for the rest of this run, so any later node can read it as {{ $run.name }}.
What it does
Section titled “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.
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.
When to use it
Section titled “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
Section titled “Inputs and settings”| Einstellung | Typ | Was es bewirkt |
|---|---|---|
| Operation | Choice | What to do to the variable. Options: Set, Add to number, Append to list, Delete. Standard: Set |
| Name | Text | Name to store the value under. Read it later as {{ $run.name }}. |
| Value | Value | The value to store. |
| Pass The Item Through | Toggle | Emit the incoming item unchanged, so this node can sit inline. Standard: On |
- Name may contain letters, digits,
_and$, and must not start with a digit, for examplecursorortotal_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, like5).
Outputs
Section titled “Outputs”-
Output
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
Section titled “Dependencies and credentials”None. This node needs no connection and has no slots for other nodes.
Example workflow
Section titled “Example workflow”Count the links on a page that point to PDFs:
- Get All Link with Output field name
linksreads the links of the open page. - Split Out with Field To Split Out
linksmakes one item per link. - Filter keeps items where
{{ $input.links }}(String) Ends With.pdf. - Set Variable with Operation Add to number, Name
pdfCount, Value1. It runs once per kept link. - A later Show Notification shows
Found {{ $run.pdfCount }} PDFs.
Common issues
Section titled “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
Section titled “Related nodes”- Get Variable: turn a stored value back into items.
- Loop: repeat steps while updating a variable.
- Data Store: remember values between runs.
- Expressions: how
$runand other expressions work.