Skip to content

Switch operator

Overview

The Switch operator is similar to Fork, but instead of propagating its input to all connected downstream blocks and having them all execute in parallel, Switch conditionally directs the data flow and causes only some downstream branches to execute.

The operator takes the value of the input key (see the block properties below) and compares it with one or more possible values, making one comparison after the other. The possible values of the input key used for comparisons are called conditions and, in addition to the value, they have:

  • A code, that is a short label
  • A comparison operator (Equal, Not equal, In, Not in, Contains, Not contains)
  • An optional descriptive name

A condition is satisfied if the expression:

Value of the input key Comparison operator Condition value

evaluates to true, for example:

label equals "en"

A default, "ELSE", condition can be enabled and it is satisfied whenever all the comparisons evaluate to false.

Connections downstream of a Switch block are not simple ways of propagating the previous block's output and triggering the execution of the next blocks. Instead, they have a property: the condition the activates the connection, so they are conditional connections.
A conditional connection is activated—meaning that the connected block is executed and receives the output of the Switch block—only if its condition evaluates to true.
To learn how to define conditional connections starting from a Switch block read the article about editing a workflow.

A Switch block can stop evaluating conditions after the first condition that is true or evaluate all the conditions. In the first case, a maximum of one downstream connection is activated, while in the second, multiple connections can be activated.

If no condition evaluates to true, the block activates the connection associated with the default condition.
If no downstream connection is associated with the default condition or the default condition itself is not enabled, 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 Switch block accepts any input.

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:

    • Key: it's the variable upon whose values the decision to follow a downstream branch instead of another is taken.
      It's a top-level key of the output of an upstream block or of the workflow, if the input format has been defined.
      It must be a string and its value is used as the left operand of all the conditions. You choose it with the key drop-down in the Input area of the block properties pop-up.

      The drop-down list is divided in groups, one group for each upstream block. Select the expand and collapse icons to the right of the block name to show or hide the sub-list of suitable output keys for that block.

      Note

      The drop-down list shows all the first-level keys that can, potentially, be available, but the keys that are actually there when executing the workflow may be less.

      You can filter the list by typing at the top of it: the list will show only keys with matching names.

      To cancel the selection of the key, select No mapping from the list or, if you already chose a key, select Clear .

  • 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 the input key must coincide with the value you type under Equals to.
        • Not Equal: the value of the input key must differ from whatever you type under Not equal to.
        • In: the value of the input 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 the input 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 the input key must contain the string you type in the Contains field.
        • Not Contains: the value of the input key must not contain the string you type under Doesn't contain.
      • Under Name you can specify an optional description for the condition.

    • 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.