Set Variable

Set Variable node is designed to create a new variable or update an existing one within your workflow. This node allows you to specify the variable's name, type, and value, providing a flexible way to manage data throughout your flow.

Properties Panel

Field

Description

Required

Node name

true

Name of variable

The name of the variable to be set or updated.

true

Type

The data type of the variable (String, Integer, Float, Boolean, Object, or Array).

true

Value

The value to be assigned to the variable.

true

Usage

  1. Specify the name of the variable you want to set or update.

  2. Select the appropriate data type for the variable.

  3. Enter the value you want to assign to the variable.

Behaviour

  • The node creates a new variable or updates an existing one with the specified name.

  • The value is converted to the specified data type before assignment.

  • For Object and Array types, the value should be a valid JSON string.

  • If the type conversion fails, the node will raise an error.

Supported Data Types

  • String: Text values

  • Integer: Non-decimal numbers

  • Float: Decimal numbers

  • Boolean: True/False values

  • Object: JSON objects

  • Array: JSON arrays

Returns

The node sets or updates the specified variable in the flow's context. You can access this variable using Magical Autocomplete (e.g., $.variables.<variable_name>) in any node below this node.

Example

Let's say you want to create a variable to store a user's age:

  1. Set Variable Name to user_age

  2. Set Variable Type to Integer

  3. Set Value to 25

This will create an integer variable named user_age with a value of 25 which can be accessed by $.variables.user_age.

Best Practices

  • Be careful when setting Object or Array types - ensure the value is a valid JSON string. For example, {"hello": "world"}

  • For complex objects or arrays, consider using a JSON formatter to ensure valid syntax when entering the value.

  • Remember that variables set with this node are accessible throughout the rest of the workflow, so plan your variable names to avoid conflicts.

Last updated