Variables

Manage typed global variables accessible from any workflow stage - like programming language variables

Overview

This node manages global workflow variables that can be accessed and modified at any stage of an n8n workflow. It allows you to initialize, set, get, view, and clear typed variables that persist throughout the workflow execution. This is useful for storing state, counters, configuration values, or any data you want to share between different nodes without passing it explicitly through input/output connections.

Common scenarios include:

  • Initializing a set of variables at the start of a workflow (e.g., counters, URLs).
  • Updating variables dynamically during workflow execution (e.g., incrementing a retry count).
  • Retrieving variable values to influence logic or API calls.
  • Viewing all current variables for debugging or logging.
  • Clearing all variables to reset state.

Practical example:

  • Initialize variables pageNumber (number) and maxRetries (number) at the beginning.
  • Increment pageNumber after each API call.
  • Check maxRetries before deciding to retry a failed request.
  • Retrieve and use these variables in HTTP Request nodes or conditional logic.

Properties

Name Meaning
Operation The action to perform on variables:
- Clear All Variables
- Get Variable
- Initialize Variables
- Set Variable
- View All Variables
Variable Name Name of the variable to set or get (required for "set" and "get" operations).
Variable Type Type of the variable value when setting it: Boolean, Date, JSON, Number, String (default: String). Only shown for "set" operation.
Variable Value Value to store in the variable, matching the selected type. Supports expressions. Different input types are shown depending on the variable type (text, number, boolean toggle, JSON editor, date picker). Only shown for "set" operation.
Initial Variables Collection of variables to initialize with name, type, and initial value. Used only in "initialize" operation.

Output

The node outputs an array of items where each item contains a json object with the following structure depending on the operation:

  • Initialize: Outputs the initialized variables merged with the incoming item JSON.
  • Set Variable: Outputs all current variables merged with the incoming item JSON.
  • Get Variable: Outputs the incoming item JSON plus:
    • operation: "get"
    • variableName: the requested variable name
    • variableValue: the value of the variable (or undefined if not found)
    • A property named after the variable containing its value
    • status: "found" or "not_found"
    • message: descriptive text about retrieval success or failure
  • View All Variables: Outputs all current variables merged with the incoming item JSON.
  • Clear All Variables: Outputs the incoming item JSON plus:
    • operation: "clear"
    • clearedVariables: array of cleared variable names
    • clearedCount: number of cleared variables
    • message: descriptive text about clearing

No binary data output is produced by this node.

Dependencies

  • No external services or APIs are required.
  • Uses n8n's internal workflow static data storage to persist variables globally within the workflow execution.
  • No special credentials or environment variables needed.

Troubleshooting

  • Missing Variable Name: For "set" and "get" operations, the variable name is required. If omitted, the node throws an error "Variable name is required".
  • Invalid Number Value: When setting a variable of type number, if the provided value cannot be converted to a valid number, an error "Invalid number value: ..." is thrown.
  • Invalid Date Value: When setting a date variable, if the date string is invalid, an error "Invalid date value: ..." is thrown.
  • Invalid JSON Value: When setting a JSON variable, if the JSON parsing fails, an error "Invalid JSON value: ..." is thrown.
  • Variable Not Found: When getting a variable that does not exist, the output indicates status "not_found" and a message stating the variable was not found.
  • Continue On Fail: If enabled, errors do not stop execution but are returned as part of the output with an "error" field.

Links and References

Discussion