Skip to main content

Assign

Assigns a boolean value (true or false) to a variable with a specified scope, making it available for use in other parts of your automation flow.

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 the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Value - The boolean value to assign (true or false). This can be:
    • A direct boolean value (true/false)
    • A variable containing a boolean value
    • A JavaScript expression that evaluates to a boolean
    • An AI-generated boolean value

Output

  • Boolean - The assigned boolean value stored in the Message scope with the name bool. This value can be accessed by subsequent nodes in the flow.

Variable Scopes

The Assign node supports multiple variable scopes for the output:

  • Message - (Default) The value is available only within the current message context
  • Local - The value is available only within the current node execution
  • Flow - The value is available across the entire flow execution
  • Global - The value is available across all flows in the application

How It Works

When executed, the Assign node:

  1. Retrieves the boolean value from the specified input source
  2. Applies thread-safe locking if using Global or Flow scope to prevent race conditions
  3. Stores the boolean value in the output variable with the configured scope
  4. Makes the value available for use by subsequent nodes

Thread Safety

The Assign node implements thread-safe operations when working with Global and Flow scopes:

  • Global scope - Uses a global mutex lock to ensure safe concurrent access across all flows
  • Flow scope - Uses a flow mutex lock to ensure safe concurrent access within the same flow
  • Message/Local scopes - No locking required as these are isolated to single execution contexts

Use Cases

1. Setting Feature Flags

// Assign a feature flag based on configuration
msg.bool = true; // Enable feature

Use the Assign node to set boolean flags that control which parts of your automation execute.

2. Storing Validation Results

After validating data, assign the result to a boolean variable:

// Result from previous validation
msg.bool = dataIsValid; // Store validation result

3. Creating Reusable Boolean Variables

Assign commonly used boolean values to Flow or Global scope variables for reuse throughout your automation:

// Set a global flag
msg.bool = isProduction; // Available across all flows

4. Conditional Flow Control

Store boolean conditions that will be used later in If nodes or other conditional logic:

msg.bool = count > 10 && status === 'active';

Examples

Example 1: Simple Boolean Assignment

Assign a true value to indicate successful initialization:

  • Input Value: true
  • Output: msg.bool = true

Example 2: Assigning from Expression

Use a JavaScript expression to calculate and assign a boolean:

  • Input Value: ${msg.age 1 or greater8}
  • Output: msg.bool = true (if age is 18 or greater)

Example 3: Flow-Scoped Variable

Assign a boolean to Flow scope for use throughout the automation:

  • Input Value: true
  • Output Scope: Flow
  • Output Name: isProcessingEnabled
  • Result: Available as flow.isProcessingEnabled throughout the flow

Example 4: Global Configuration Flag

Set a global boolean flag for application-wide configuration:

  • Input Value: ${env.DEBUG_MODE === 'true'}
  • Output Scope: Global
  • Output Name: debugEnabled
  • Result: Available as global.debugEnabled in all flows

Tips for Effective Use

  1. Choose the Right Scope

    • Use Message scope for values needed only in the current execution
    • Use Flow scope for values shared across nodes in the same flow
    • Use Global scope for application-wide settings that rarely change
  2. Meaningful Variable Names

    • When changing the output name, use descriptive names like isValid, hasPermission, shouldProcess
    • This makes your flow logic self-documenting and easier to maintain
  3. Initialize Early

    • Place Assign nodes at the beginning of your flow to set default values
    • This prevents undefined variable errors in conditional logic
  4. Combine with Expressions

    • Use JavaScript expressions in the Value input to create dynamic boolean assignments
    • Example: ${msg.count > 0 && msg.status === 'active'}
  5. Documentation

    • Use the Name property to describe what the boolean represents
    • Example: "Assign Validation Result" or "Set Debug Flag"

Common Errors and Solutions

Error: "Value is undefined"

Cause: The input value source (variable or expression) doesn't exist or hasn't been set.

Solution:

  • Ensure the variable is set by a previous node
  • Use a default value or add error handling
  • Check that the JavaScript expression syntax is correct

Error: "Type mismatch"

Cause: The input value is not a boolean type.

Solution:

  • Convert the value to boolean using JavaScript: ${!!msg.value}
  • Use comparison operators to get a boolean: ${msg.count > 0}
  • Ensure the source data is actually boolean

Error: "Race condition in concurrent flows"

Cause: Multiple flows are trying to modify the same Global or Flow variable simultaneously without proper synchronization.

Solution:

  • The Assign node handles this automatically with mutex locks
  • Ensure you're using the correct scope for your use case
  • Consider using Message scope if concurrent access isn't required

Best Practices

  1. Default to Message Scope - Use Message scope unless you have a specific reason to use Flow or Global scope
  2. Avoid Global State - Minimize use of Global scope to prevent unexpected interactions between flows
  3. Clear Naming - Use descriptive output variable names when changing from the default bool
  4. Test Edge Cases - Verify behavior when input values are undefined, null, or unexpected types
  5. Document Complex Logic - Add comments or use descriptive node names when assigning from complex expressions
  • Operation - Perform logical operations (AND, OR, XOR, etc.) on multiple boolean values
  • ToString - Convert the assigned boolean value to a string representation
  • If - Use the assigned boolean value for conditional flow control
  • Switch - Make decisions based on the assigned boolean value