Overview
This node manages global workflow variables that are accessible throughout the entire workflow execution. It allows you to initialize, set, get, view, and clear typed variables similar to how variables work in programming languages. This is useful for storing state, counters, configuration values, or any data you want to persist and reuse across multiple nodes and executions.
A common scenario is initializing a set of variables at the start of a workflow (e.g., URLs, counters, flags), then updating or retrieving them later in the workflow to control logic or pass data dynamically. For example, you might initialize a variable maxPages
to 10, increment a pageNumber
variable as you paginate through API results, or store a JSON object with user preferences.
Properties
Name | Meaning |
---|---|
Initial Variables | A collection of variables to initialize at once. Each variable has: - Name: The variable's identifier (e.g., URL, counter). - Type: Data type of the variable ( Boolean , Date , JSON , Number , String ). - Value: Initial value matching the selected type. |
Usage Guide | Informational text explaining how to access these variables in other nodes using expressions like $workflow.variables.VARIABLE_NAME . |
Details on "Initial Variables" sub-properties:
- Name: Required string to identify the variable.
- Type: One of Boolean, Date, JSON, Number, or String.
- Value: Initial value corresponding to the chosen type:
- String: Text value.
- Number: Numeric value.
- Boolean: True or false.
- JSON: JSON object or array.
- Date: Date/time value.
Output
The node outputs an array of items where each item’s json
property contains the current state of variables after the operation:
- For Initialize Variables operation, the output JSON includes all initialized variables with their names and values merged with the input item’s JSON.
- Variables are stored globally and can be accessed or updated by other operations.
- No binary data is produced by this node.
Example output snippet after initialization:
{
"URL": "https://example.com",
"counter": 0,
"isActive": true
}
Dependencies
- No external services or APIs are required.
- Uses n8n’s internal static workflow data storage to persist variables globally during workflow execution.
- No special environment variables or credentials needed.
Troubleshooting
- Variable name is required error: Occurs if you try to set or get a variable without specifying its name. Ensure the variable name field is filled.
- Invalid number value: When setting a variable of type number, if the provided value cannot be converted to a valid number, an error is thrown. Provide a valid numeric value.
- Invalid date value: When setting a date variable, if the date string is invalid or unparsable, an error occurs. Use ISO date strings or valid date formats.
- Invalid JSON value: If the JSON value is malformed or not parseable, an error will be raised. Make sure JSON inputs are correctly formatted.
- Clearing variables removes all stored variables; use with caution to avoid losing important state.