IfElse Function
The IfElse Function node is a utility component that allows for conditional branching in workflows based on custom JavaScript functions. It evaluates an “If” condition and routes the flow accordingly, executing either the “If” or “Else” function.
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
-
Input Variables
-
Label: Input Variables
-
Name: functionInputVariables
-
Type: JSON
-
Optional: Yes
-
Description: Input variables that can be used in the function with a ‘var)
-
Accepts variables and lists
-
-
IfElse Name
-
Label: IfElse Name
-
Name: functionName
-
Type: String
-
Optional: Yes
-
Placeholder: “If Condition Match”
-
-
If Function
-
Label: If Function
-
Name: ifFunction
-
Type: Code (JavaScript)
-
Description: Function that must return a value
-
Default:
-
-
Else Function
-
Label: Else Function
-
Name: elseFunction
-
Type: Code (JavaScript)
-
Description: Function that must return a value
-
Default:
-
Outputs
-
True
-
Label: True
-
Name: returnTrue
-
Base Classes: string, number, boolean, json, array
-
Is Anchor: Yes
-
-
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
-
Custom JavaScript Execution: Uses NodeVM for secure execution of user-defined JavaScript.
-
Variable Integration: Allows use of input variables, flow context, and system variables within functions.
-
Flexible Output: Can return various data types (string, number, boolean, JSON, array).
-
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.