Switch
Use this node when you need to route a message to one or more named connections based on custom logic — for example, routing to High, Normal, or Low based on a sensor reading, or fanning a single message out to multiple parallel paths simultaneously. The script returns a connection name or an array of names.
Configuration
Section titled “Configuration”- Script language — required. Choose
TBELorJavaScript. - Script body — required. A function that receives three arguments and must return either a string or an array of strings (each string is a connection label):
msg— the message data (object or array).metadata— the message metadata. In JavaScript, an object where all values are strings; in TBEL, ajava.util.Map<String, String>.msgType— the message type as a string.
Message processing algorithm
Section titled “Message processing algorithm”- Select the script based on the configured Script language.
- Execute the script function.
- Interpret the return value:
- A string → treated as a one-element list; route the message via that connection.
- An array of strings → route the message via each listed connection.
- Any other type, or an exception → route via
Failure.
Output connections
Section titled “Output connections”| Connection | Condition |
|---|---|
| (any name returned by the script) | The message is routed via every connection name the script returns. |
Failure | The script returned an invalid type (e.g., number, object) or threw an exception. |
Examples
Section titled “Examples”Example 1 — Single string return → A
Section titled “Example 1 — Single string return → A”{ "scriptLang": "TBEL", "tbelScript": "return 'A';"}Result: routed via A — a string is treated as a one-element list.
Example 2 — One-element array → A
Section titled “Example 2 — One-element array → A”{ "scriptLang": "TBEL", "tbelScript": "return ['A'];"}Result: routed via A.
Example 3 — Multiple connections → A, B, C
Section titled “Example 3 — Multiple connections → A, B, C”{ "scriptLang": "TBEL", "tbelScript": "return ['A', 'B', 'C'];"}Result: the message is forwarded to all three connections simultaneously.
Example 4 — Dynamic routing by temperature → High
Section titled “Example 4 — Dynamic routing by temperature → High”Incoming message
Data:
{ "temperature": 85}Node configuration
{ "scriptLang": "TBEL", "tbelScript": "var t = msg.temperature;\nif (t > 80) return 'High';\nif (t > 60) return 'Normal';\nreturn 'Low';"}Result: routed via High — temperature (85) exceeds 80.
JSON schema
Section titled “JSON schema”{ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "TbJsSwitchNodeConfiguration", "type": "object", "required": ["scriptLang"], "properties": { "scriptLang": { "type": "string", "description": "Scripting language used to execute the function.", "enum": ["TBEL", "JS"] }, "jsScript": { "type": "string", "description": "JavaScript function body that must return a string or array of strings. Used when 'scriptLang' is 'JS'." }, "tbelScript": { "type": "string", "description": "TBEL function body that must return a string or array of strings. Used when 'scriptLang' is 'TBEL'." } }, "additionalProperties": false}