Skip to content

Switch

Overview

The Switch node compares an input value against a list of switch values and returns a matching result if found. This node is useful for branching logic based on predefined input options within your automation workflows.


Purpose

Use this node to implement conditional routing or branching logic in workflows by comparing a user input against a list of possible values.


Inputs

InputTypeDescription
Switch InputTextThe input value to be evaluated against the list of switch values.
Switch ValuesJSON ArrayA JSON array of values to compare with the input. Example: ["Option1", "Option2", "Option3"]

Outputs

This node sets the statusReturn property to the matching switch value if found, or "default" if no match is found.

Output Variable NameDescription
statusReturnThe matching switch value from the list if found; otherwise returns "default".

Execution Details

  1. Validation:

    • Validates presence of Switch Input and Switch Values inputs.
    • Validates that Switch Values is a valid, non-empty JSON array.
  2. Switch Logic Execution:

    • Iterates through the list of switch values.
    • Uses _fm.PropReplacePlaceholders to replace any placeholders in each switch value with data from the workflow context.
    • Compares each processed switch value with the Switch Input.
    • If a match is found, sets statusReturn to the matched value and exits.
  3. Default Handling:

    • If no match is found, sets statusReturn to "default".
  4. Error Handling:

    • Returns failure if inputs are missing, invalid, or if any unhandled exception occurs during execution.

Example Use Cases

  • Routing workflow execution paths based on user selection or input values.
  • Implementing simple decision trees without complex conditional nodes.
  • Mapping input strings to predefined outputs for classification or dispatch logic.

Notes

⚠️ Important:

  • The Switch Values input must be a valid JSON array. Example:

    json
    ["Yes", "No", "Maybe"]

Tentech 2024