Skip to main content

Assign

Assigns a numeric value to a variable with support for different scopes (Message, Flow, Global, Custom).

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.

Input

  • Value - The numeric value to assign. Can be a constant number, a variable, or a JavaScript expression that evaluates to a number.

Output

  • Number - The assigned numeric value stored in the specified variable. Default output variable name is num.
    • Scope - Determines where the variable is stored:
      • Message - Variable is available only within the current message context
      • Flow - Variable is shared across the entire flow
      • Global - Variable is shared across all flows in the robot
      • Custom - Specify a custom variable name and scope

Examples

Example 1: Assign a Constant Value

Assign the number 100 to a variable for later use in calculations:

// Input Value
100

Output: num = 100

Example 2: Initialize a Counter

Create a counter variable in Flow scope to track iterations across multiple nodes:

// Input Value
0

Set Output Scope to Flow and name it counter.

Example 3: Calculate and Assign

Assign the result of a calculation using JavaScript:

// Input Value (JavaScript expression)
${msg.price * msg.quantity}

This calculates the total based on price and quantity from the message context.

Example 4: Global Configuration Value

Store a configuration value that should be accessible across all flows:

// Input Value
30

Set Output Scope to Global and name it maxRetries.

Tips for Effective Use

  1. Choose the Right Scope:

    • Use Message scope for temporary values within a single flow execution
    • Use Flow scope for counters and values shared across nodes in the same flow
    • Use Global scope sparingly for configuration values or shared state
  2. Variable Naming:

    • Use descriptive names for custom variables (e.g., orderTotal, retryCount)
    • The default num is fine for temporary calculations
  3. Thread Safety:

    • The Assign node uses mutex locks for Flow and Global scopes to prevent race conditions
    • This ensures safe concurrent access in parallel flow executions
  4. Type Conversion:

    • The node expects numeric input. Use JavaScript to convert strings: ${parseFloat(msg.value)}
    • Non-numeric values will cause an error

Common Use Cases

  • Initialize Counters: Set a counter to 0 before a loop
  • Store Configuration: Save numeric settings like timeouts, limits, or thresholds
  • Calculate Totals: Store the result of mathematical operations
  • Set Default Values: Provide fallback values for optional parameters

Common Errors and Solutions

Error: "Value is not a number"

Cause: The input value cannot be converted to a number.

Solution: Ensure the input is numeric or use JavaScript to convert:

${parseFloat(msg.textValue) || 0}

Error: "Variable not found in scope"

Cause: Trying to read a variable from a scope where it doesn't exist.

Solution: Verify the variable was assigned with the correct scope and name before trying to use it.

Race Condition in Global Variables

Cause: Multiple flows accessing the same global variable simultaneously.

Solution: The Assign node handles this automatically with mutex locks. However, for complex state management, consider using Flow scope or dedicated state management tools.