> For the complete documentation index, see [llms.txt](https://docs.b2winsuite.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.b2winsuite.com/scripting/scripting-in-b2data/custom-script-nodes/switch-case.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
