Switch case

This node enables you to evaluate an input value against multiple predefined cases and route the flow to the corresponding output port based on the matching case.

Example:

/**
 * Write your code here
 * For example a random condition that returns 0, 1 or 2 and output them to a different output port
 */
return Math.round(Math.random() * 10) % 3;

Or for a more intuitive example:

var fileName = NodeInputReader.inputAsFile().getName();

// which department to work with
if (fileName.contains("Accounting")) {
    return 0; // Accounting output
} else if (fileName.contains("Human_Resources")) {
    return 1; // Human Resources output
} else {
    return 2; // Development output
}

In this example the node will evaluates the name of the input file and determines the relevant department based on predefined cases. Depending on the department identified in the file name, the workflow routes to the corresponding output port:

  • Port 0 (Accounting): If the file name contains "Accounting," the flow is routed to the Accounting output port.

  • Port 1 (Human Resources): If the file name contains "Human_Resources," the flow is routed to the Human Resources output port.

  • Port 2 (Development): If the file name does not match "Accounting" or "Human_Resources," it defaults to the Development output port.

Last updated