Actions2
Overview
This node allows users to set or retrieve global variables that are scoped to the workflow execution. It uses a persistent storage mechanism within the workflow context to store data that can be shared across different executions or nodes in the same workflow.
Common scenarios include:
- Storing counters or accumulators that track occurrences or sums during workflow runs.
- Saving user-specific or session-specific data that needs to be accessed by multiple nodes.
- Caching intermediate results to avoid redundant processing.
For example, you could use this node to increment a global counter each time an event occurs, or to save a user ID retrieved from one API call and reuse it later in the workflow.
Properties
Name | Meaning |
---|---|
Variable Name | The unique name for the global variable (case-sensitive). Examples: myCounter , user.ID . |
Additionally, depending on the operation selected:
Name | Meaning |
---|---|
Operation | Choose between "Set Variable" (store a value) or "Get Variable" (retrieve a value). |
Value | When setting a variable, specify the value to store. Can be a simple value or JSON data. |
Output
The node outputs an array of items corresponding to the input items processed.
For Set Variable operation:
- Each output item contains the original input JSON merged with a
_globalVariableSet
object detailing:name
: the variable name set.value
: the value stored.status
: always"success"
if no error occurred.
- Each output item contains the original input JSON merged with a
For Get Variable operation:
- Each output item contains the original input JSON merged with a new property named after the variable, holding its stored value.
In case of errors (e.g., empty variable name), if the node is configured to continue on failure, the output item will contain an
error
field describing the issue along with the original input.
The node does not output binary data.
Dependencies
- No external services or APIs are required.
- Uses n8n's internal workflow static data storage to persist variables.
- No special environment variables or credentials needed.
Troubleshooting
- Empty Variable Name Error: The node throws an error if the "Variable Name" property is empty. Ensure this field is filled with a valid, non-empty string.
- JSON Parsing Issues: When setting a variable, if the value is a string representing JSON, the node attempts to parse it. Malformed JSON strings may cause unexpected behavior; ensure JSON syntax is correct.
- Data Persistence Scope: Variables are stored in workflow static data, which persists only within the workflow context. They are not shared across different workflows or globally outside the current workflow.
- Continue On Fail Behavior: If enabled, errors do not stop execution but are returned as part of the output JSON under an
error
key.