Switch operator
Overview
The Switch operator is similar to Fork, but instead of having all the downstream blocks executed in parallel, Switch, together with outgoing conditional connections, causes only selected downstream branches to be followed.
The operator has only one input variable named key
(string) and the user defines or more conditions, each made of:
- A value
- A comparison operator (Equal, Not equal, In, Not in, Contains, Not contains)
- A code, that is a short label of maximum four characters
- An optional descriptive name
When the block is executed, conditions are evaluated. A condition is satisfied if the expression:
Value of input variable 'key' comparison operator condition value
evaluates to true, for example:
key equals "en"
A default condition with code ELSE can be enabled. It is satisfied whenever all the other conditions are not.
A Switch block can stop evaluating conditions after one is satisfied or evaluate all of them.
At the end of the evaluation of the conditions, there is a set—potentially empty!—of satisfied conditions: the flow follows only the conditional connections associated with the codes of satisfied conditions.
For example, if key
value is de and these four conditions are defined:
Code | Comparison operator | Value |
---|---|---|
EN | Equal | en |
DE | Equal | de |
IT | Equal | it |
ELSE | N/A | N/A |
the only condition satisfied is DE. If four conditional connections associated with the four condition codes start from the Switch block, only the one associated with the GERM code is followed.
If no condition is satisfied, the flow follows the connection associated with the ELSE condition, if any. If no downstream connection is associated with the ELSE condition or the default condition itself is not enabled in the Switch block, the workflow returns an error.
All the branches starting from a Switch block must converge into an End Switch block. The connection associated with the default condition, if any, can terminate directly in the End Switch block when no other block is required in between.
Workflows containing Switch blocks can only be published in asynchronous mode.
Input
A block of the Switch operator has this input variable:
key
(string): the variable whose values is tested in the conditions.
Block properties
The properties of a Switch block are accessible by editing the block and are divided into three groups:
-
Basic properties:
- Block name
- Component version (read only)
- Block ID (read only)
-
Input: this property corresponds to the input variable.
It is read-only—so only descriptive of the expected input—when the block is the first in a flow and the workflow's input has not been explicitly described. In that case the workflow's input JSON must contain a key whose name and type match those of the input variable.
Otherwise, it is editable and must be set. -
Functional:
- Multiple: toggle switch. When it is on, all conditions are evaluated, when it is off the evaluation stops after the first condition that is satisfied.
- Default condition: toggle switch. When it is turned on, the default condition is available. The default condition code is ELSE and cannot be changed, but it is possible to associate an extended name to the condition in the Name field.
-
Conditions: these are the expressions that are evaluated to determine the downstream connections to activate.
-
To add a condition select Add condtion at the top right corner of the pop-up. A pane for the new condition is added below the existing conditions.
- If you want, you can change the default code of the condition (for example 001 for the first condition, 002 for the second and so on) by editing the Code field.
The code is the short label for the condition that is used when configuring the conditional connections in the diagram. -
Under Rule select the operator of the condition choosing between:
- Equal: the value of input variable
key
must coincide with the value you type under Equals to. - Not Equal: the value of input variable
key
must differ from whatever you type under Not equal to. -
In: the value of input variable
key
must be one of those listed under Contained in.- To add a value to the list, select the plus icon under Contained in and fill the new field the is appended to the bottom of the list.
- To change a value in the list, just edit it.
- To delete a value from the list select Remove value to the right of it.
-
Not In: the value of input variable
key
must not be included in the list under Not contained in. The list of values is managed like that of the In operator (see above). - Contains: the value of input variable
key
must contain the string you type in the Contains field. - Not Contains: the value of input variable
key
must not contain the string you type under Doesn't contain.
- Equal: the value of input variable
-
Under Name you can specify an optional description for the condition.
- If you want, you can change the default code of the condition (for example 001 for the first condition, 002 for the second and so on) by editing the Code field.
-
To modify an already defined condition, simply select its pane and modify the fields as desired.
If you change the operator, that is the value under Rule, you may also need to change the value or the list of values: based on the operator, do it as if you were adding a new condition (see above). -
To delete a condition, select the corresponding pane near its border then select Remove condtion of the toolbar at the top right corner of the pop-up.
-
Outputs
The output that a Switch block transmits to the dowstream blocks along the activated connections is the echo of its input.