Variables Set icon

Variables Set

Set global variables (alternative to paid Variables feature)

Overview

The "Variables Set" node allows users to manage global variables within an n8n workflow without requiring the paid Variables feature. It supports setting single or multiple variables, deleting a variable, and clearing all variables. This node is useful for workflows that need to store and reuse data dynamically across different executions or nodes.

Common scenarios include:

  • Storing intermediate results or flags as variables to influence later workflow steps.
  • Setting multiple configuration values at once from a JSON object.
  • Cleaning up variables when they are no longer needed to avoid stale data.

Practical example:

  • A workflow sets a variable named userStatus to "active" after a user logs in, then later checks this variable to decide whether to send a notification.
  • Another workflow sets multiple variables like { "threshold": 10, "isEnabled": true } from a JSON input to configure subsequent processing logic.

Properties

Name Meaning
Operation The action to perform:
- Set Variable: Set a single variable
- Set Multiple Variables: Set multiple variables from an object
- Delete Variable: Remove a variable
- Clear All Variables: Remove all variables (requires confirmation)
Variable Name Name of the variable to set or delete (required for "set" and "delete" operations)
Variable Value Value to store in the variable (required for "set" operation)
Value Type Type of the variable value for "set" operation: String, Number, Boolean, or JSON
Variables Object JSON object containing multiple variables to set (required for "setMultiple" operation)
Confirm Clear Boolean flag to confirm clearing all variables (required for "clear" operation)

Output

The node outputs an array of JSON objects describing the result of each operation:

  • For Set Variable:
    {
      "operation": "set",
      "variableName": "myVariable",
      "value": <typed_value>,
      "type": "<value_type>",
      "success": true
    }
    
  • For Set Multiple Variables:
    {
      "operation": "setMultiple",
      "results": [
        { "name": "var1", "value": <value>, "success": true },
        { "name": "var2", "value": <value>, "success": false }
      ],
      "totalCount": <number_of_variables_attempted>,
      "successCount": <number_of_successful_sets>
    }
    
  • For Delete Variable:
    {
      "operation": "delete",
      "variableName": "myVariable",
      "deleted": true,
      "success": true
    }
    
  • For Clear All Variables:
    {
      "operation": "clear",
      "clearedCount": <number_of_variables_cleared>,
      "success": true
    }
    

If an error occurs during execution and "Continue On Fail" is enabled, the output will contain an error message and success will be false.

This node does not output binary data.

Dependencies

  • Uses an internal shared module for variable storage management.
  • No external API or service dependencies.
  • Requires appropriate permissions to read/write global variables within the n8n environment.

Troubleshooting

  • Missing Variable Name: When setting or deleting a variable, if the variable name is empty, the node throws an error "Variable name is required". Ensure you provide a valid variable name.
  • Invalid Number Value: If the value type is set to Number but the provided value cannot be converted to a number, an error "Invalid number value" is thrown. Provide a valid numeric string.
  • Invalid JSON Value: For JSON value types or the variables object in "setMultiple", invalid JSON strings cause errors "Invalid JSON value" or "Invalid JSON in variables object". Validate your JSON syntax before input.
  • Clear Confirmation Missing: When using the "clear" operation, you must explicitly confirm by enabling the confirmation property; otherwise, an error "You must confirm clearing all variables" is thrown.
  • Unknown Operation: If an unsupported operation is selected, the node throws "Unknown operation" error.
  • To resolve errors, check input parameters carefully and ensure correct types and formats.

Links and References

Discussion