Variables Set icon

Variables Set

Set global variables (alternative to paid Variables feature)

Overview

This 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 individual variables, and clearing all stored variables. This is useful for workflows that need to persist data across executions or share state between different parts of a workflow.

Practical examples include:

  • Storing API tokens or session identifiers globally for reuse.
  • Setting multiple configuration parameters at once from a JSON object.
  • Cleaning up all stored variables before starting a new workflow run.

Properties

Name Meaning
Operation The action to perform:
- Set Variable
- Set Multiple Variables
- Delete Variable
- Clear All Variables
Variable Name The name of the variable to set or delete (required for "Set Variable" and "Delete Variable" operations)
Variable Value The value to assign to the variable (used only in "Set Variable" operation)
Value Type The type of the variable value: String, Number, Boolean, or JSON (used only in "Set Variable")
Variables Object A JSON object containing multiple variables to set (used only in "Set Multiple Variables")
Confirm Clear Confirmation boolean to allow clearing all variables (used only in "Clear All Variables")

Output

The node outputs a JSON object describing the result of the performed operation:

  • For Set Variable:

    {
      "operation": "set",
      "variableName": "name_of_variable",
      "value": "value_set",
      "type": "value_type",
      "success": true
    }
    
  • For Set Multiple Variables:

    {
      "operation": "setMultiple",
      "results": [
        {"name": "var1", "value": "value1", "success": true},
        {"name": "var2", "value": "value2", "success": true}
      ],
      "totalCount": 2,
      "successCount": 2
    }
    
  • For Delete Variable:

    {
      "operation": "delete",
      "variableName": "name_of_variable",
      "deleted": true,
      "success": true
    }
    
  • For Clear All Variables:

    {
      "operation": "clear",
      "clearedCount": number_of_variables_cleared,
      "success": true
    }
    

If an error occurs and the node is configured to continue on failure, the output will contain an error message and success set to false.

The node does not output binary data.

Dependencies

  • Uses an internal shared module for variable storage management.
  • No external services or API keys are required.
  • No special environment variables or n8n credentials needed.

Troubleshooting

  • Invalid JSON in Variables Object: When using "Set Multiple Variables," ensure the JSON object is valid. Invalid JSON will cause an error.
  • Missing Variable Name: For "Set Variable" and "Delete Variable" operations, the variable name must be provided; otherwise, an error is thrown.
  • Invalid Number Value: If the value type is set to Number but the value cannot be converted to a valid number, an error occurs.
  • Invalid JSON Value: For "Set Variable" with JSON type, the value must be valid JSON.
  • Clear Confirmation Missing: To clear all variables, the confirmation checkbox must be checked; otherwise, the node throws an error.
  • Unknown Operation: If an unsupported operation is selected, the node will throw an error indicating the unknown operation.

To resolve these issues, verify input values carefully and ensure all required fields are correctly filled.

Links and References

Discussion