Conditional split
The Conditional Split component allows you to route an input message into one specific output based on the expressions associated with each output. The message is routed to the first expression that evaluates to true
. If none of the expressions evaluate to true
, the message will be sent to the default output if one is configured.
Configuration
The component has two configurable fields:
- Conditions:
- Output name: This is the name assigned to the output.
- Expression: Defines a logical condition for the output.
- Default output: This field is optional and serves as a fallback destination. In case none of the expressions evaluate to
true
, the message will be routed here. It is possible to specify the name of an existing output or use a different name to create a new default output.
It is only possible to define up to 26 distinct outputs for each Conditional Split. In the unlikely case you need more, it is possible to connect a second Conditional Split to the default output of the first Conditional Split.
Expressions example
Data:
{
"_id" : "0df1cda7b0111736c69cb10a7eddd072",
"kind" : "RECORD",
"migration" : {
"migrate" : true
}
}
Expressions:
kind == "RECORD"
evaluates to true
migration.migrate == false
evaluates to false
Expression Reference
Values
Accessing values is done using the dot-notation.
Unary operators
Operation: (Symbol)
Negate (!)
Example to check if a property exists:
!name
evaluates to true
if name
is not defined in the incoming message.
Binary operators
Operation: (Symbol)
Add, Concat (+)
Subtract (-)
Multiply (\*)
Divide (/)
Divide and floor (//)
Modulus (%)
Power of (^)
Logical AND (&&)
Logical OR (||)
Comparisons
Comparison: (Symbol)
Equal (==)
Not equal (!=)
Greater than (>)
Greater than or equal (>=)
Less than (<)
Less than or equal (<=)
Element in array or string (in)
The in operator can be used to check for a substring: "Cad" in "Ron Cadillac", and it can be used to check for an array element: "coarse" in ['fine', 'medium', 'coarse']. However, the ==
operator is used behind the scenes to search arrays, so it should not be used with arrays of objects. The following expression returns false: {a: 'b'}
in [{a: 'b'}]
.
Ternary operator
Conditional expressions check to see if the first segment evaluates to a truthy value. If so, the consequent segment is evaluated. Otherwise, the alternate is. If the consequent section is missing, the test result itself will be used instead. Expression -> (Result)
"" ? "Full" : "Empty" -> (Empty)
"foo" in "foobar" ? "Yes" : "No" -> (Yes)
{agent: "Archer"}.agent ?: "Kane" -> (Archer)
Value functions
startsWith(key, startsWith)
endsWith(key, endsWith)
includes(key, includes)
substring(key, start, end)
length(key)
toLowerCase(key)
toUpperCase(key)
Data:
{
name: "John",
age: 34,
address: { street: "1 Holland road" },
platformsOwned: ["PC", "Xbox"],
}
Expression -> (Result)
startsWith(name, "Joh") -> (TRUE)
endsWith(name, "hn") -> (TRUE)
includes(name, "Joh") -> (TRUE)
substring(name, 0, 1) -> (J)
length(name) -> (4)
toLowerCase(name) -> (john)
toUpperCase(name) -> (JOHN)
Native Types
Type: (Examples)
Booleans (true, false)
Strings ("Hello "user"", 'Hey there!')
Numerics (6, -7.2, 5, -3.14159)
Objects ({hello: "world!"})
Arrays (['hello', 'world!'])
Groups
Parentheses work just how you'd expect them to: Expression -> (Result)
(83 + 1) / 2 -> (42)
1 < 3 && (4 > 2 || 2 > 4) -> (true)
Input
-
Name: Input
- Description: Any message with an object.
Output
- Description The input messages split to the outputs.