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. It provides operations to set a single variable, set multiple variables at once from an object, delete a specific variable, or clear all variables. This is useful for workflows that need to store and reuse data across different executions or nodes without relying on paid features.

Practical examples include:

  • Storing API tokens or session IDs globally after fetching them once.
  • Deleting sensitive information when no longer needed.
  • Clearing all stored variables as part of a reset or cleanup process.
  • Setting multiple configuration parameters in one step from a JSON object.

Properties

Name Meaning
Operation The action to perform: "Set Variable", "Set Multiple Variables", "Delete Variable", or "Clear All Variables".
Variable Name Name of the variable to set or delete (required for "set" and "delete" operations).
Variable Value Value to store in the variable (used only with "set" operation).
Value Type Data type of the variable value: String, Number, Boolean, or JSON (used only with "set").
Variables Object JSON object containing multiple variables to set (used only with "setMultiple").
Confirm Clear Boolean confirmation required to clear all variables (used only with "clear").

Output

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

  • For set:
    {
      "operation": "set",
      "variableName": "name_of_variable",
      "value": "stored_value",
      "type": "value_type",
      "success": true
    }
    
  • For setMultiple:
    {
      "operation": "setMultiple",
      "results": [
        {"name": "var1", "value": "value1", "success": true},
        {"name": "var2", "value": "value2", "success": true}
      ],
      "totalCount": 2,
      "successCount": 2
    }
    
  • For delete:
    {
      "operation": "delete",
      "variableName": "name_of_variable",
      "deleted": true,
      "success": true
    }
    
  • For clear:
    {
      "operation": "clear",
      "clearedCount": number_of_cleared_variables,
      "success": true
    }
    

No binary data output is produced by this node.

Dependencies

  • Uses an internal VariablesStorage class to handle variable persistence.
  • No external API or service dependencies.
  • Requires no special credentials but depends on proper node parameter configuration.

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".
  • Invalid Number Value: If the value type is set to Number but the provided value cannot be converted to a valid number, an error "Invalid number value" is thrown.
  • Invalid JSON Value: For JSON type values or the variables object in "setMultiple", invalid JSON input causes an error "Invalid JSON value" or "Invalid JSON in variables object".
  • Clear Confirmation Missing: Attempting to clear all variables without confirming via the "Confirm Clear All" property results in an error "You must confirm clearing all variables".
  • Unknown Operation: If an unsupported operation is selected, the node throws "Unknown operation".

To resolve these errors, ensure all required fields are correctly filled, JSON inputs are valid, and confirmations are explicitly given where needed.

Links and References

Discussion