# 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:

```typescript
/**
 * 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:

```typescript
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.

<figure><img src="/files/vvK7L2u1ObMuYzL1kH54" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.b2winsuite.com/5.5/scripting/scripting-in-b2data/custom-script-nodes/switch-case.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
