Actions2
Overview
This node allows users to set or get workflow-scoped global variables within an n8n workflow. It uses the workflow's static data storage to persist values across executions, enabling data sharing between different parts of a workflow or even across multiple workflow runs.
Common scenarios include:
- Storing counters or flags that track how many times a workflow has run.
- Saving user-specific or session-specific data that needs to be accessed by multiple nodes.
- Caching API responses or intermediate results to avoid redundant calls.
For example, you can use this node to increment a global counter each time a workflow executes or store a JSON object representing user preferences that other nodes can read later.
Properties
Name | Meaning |
---|---|
Variable Name | The unique name for the global variable (case-sensitive). Examples: myCounter , user.ID . |
Value | The value to store in the global variable. Can be a simple value (string, number, boolean) or a JSON structure (object/array). Supports expressions for dynamic content. |
Output
The node outputs an array of items corresponding to the input items processed:
For the Set Variable operation:
- Each output item contains the original input JSON merged with a
_globalVariableSet
object. - The
_globalVariableSet
object includes:name
: The variable name that was set.value
: The value stored.status
: Always"success"
indicating the variable was set successfully.
- Each output item contains the original input JSON merged with a
For the Get Variable operation:
- Each output item contains the original input JSON merged with a new property named after the variable name.
- This property holds the value retrieved from the global variable store.
No binary data is produced by this node.
Dependencies
- Uses n8n's internal workflow static data storage to persist global variables.
- No external services or API keys are required.
- Requires proper permissions to access and modify workflow static data.
Troubleshooting
- Empty Variable Name Error: If the "Variable Name" property is empty, the node throws an error stating "Variable Name cannot be empty." Ensure this field is filled with a valid string.
- JSON Parsing Issues: When setting a variable, if the value is a string that looks like JSON, the node attempts to parse it. Malformed JSON strings may cause unexpected behavior. Use valid JSON or expressions to define complex values.
- Data Persistence: Variables are stored in workflow static data, which persists across executions but is scoped to the workflow. Variables won't be shared across different workflows.
- Continue On Fail: If enabled, errors during processing individual items will not stop the entire execution; instead, error details are returned in the output for those items.