Node Details

  • Name: ifElseFunction

  • Label: IfElse Function

  • Type: IfElseFunction

  • Category: Utilities

  • Version: 2.0

  • Description: Split flows based on If Else javascript functions

Input Parameters

  1. Input Variables

    • Label: Input Variables

    • Name: functionInputVariables

    • Type: JSON

    • Optional: Yes

    • Description: Input variables that can be used in the function with a ‘prefix(e.g.,' prefix (e.g., var)

    • Accepts variables and lists

  2. IfElse Name

    • Label: IfElse Name

    • Name: functionName

    • Type: String

    • Optional: Yes

    • Placeholder: “If Condition Match”

  3. If Function

    • Label: If Function

    • Name: ifFunction

    • Type: Code (JavaScript)

    • Description: Function that must return a value

    • Default:

      if ("hello" == "hello") {
          return true;
      }
      
  4. Else Function

    • Label: Else Function

    • Name: elseFunction

    • Type: Code (JavaScript)

    • Description: Function that must return a value

    • Default:

      return false;
      

Outputs

  1. True

    • Label: True

    • Name: returnTrue

    • Base Classes: string, number, boolean, json, array

    • Is Anchor: Yes

  2. False

    • Label: False

    • Name: returnFalse

    • Base Classes: string, number, boolean, json, array

    • Is Anchor: Yes

Functionality

The IfElse Function node evaluates the provided “If” function. If it returns true, the node outputs the result through the “True” output. Otherwise, it executes the “Else” function and outputs the result through the “False” output.

Key Features

  1. Custom JavaScript Execution: Uses NodeVM for secure execution of user-defined JavaScript.

  2. Variable Integration: Allows use of input variables, flow context, and system variables within functions.

  3. Flexible Output: Can return various data types (string, number, boolean, JSON, array).

  4. Sandbox Environment: Executes code in a controlled environment with configurable dependencies.

Use Cases

  • Implementing complex conditional logic in workflows

  • Dynamically routing data based on custom conditions

  • Performing data transformations or validations before proceeding in a flow

Technical Notes

  • Utilizes NodeVM for sandboxed JavaScript execution

  • Supports both built-in and external dependencies (configurable via environment variables)

  • Handles JSON parsing and stringification for input variables

  • Manages escape characters in string inputs and outputs

Security Considerations

  • Executes user-defined code in a sandboxed environment

  • Configurable limitations on available dependencies and built-in modules

This node provides a powerful way to implement custom logic and conditional branching within agentic solutions, allowing for complex decision-making processes based on runtime data and conditions.