Condition
  • 01 Jun 2023
  • 4 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Condition

  • Dark
    Light
  • PDF

Article Summary

The Condition node enables you to direct the flow of a task based on specific requirements set by the user. The node consists of one or more condition blocks, each of which includes one or more conditions and a single output edge. When a task enters this node, it is evaluated against each condition in the topmost condition block. If the task satisfies every condition in the block, it follows that block's output edge. If not, it moves on to the next block. If a task fails to meet the conditions of every block, it follows the node's default output edge (see Picture 1).

Condition.png

Picture 1. Condition node task flow

Essentially, the Condition node functions as an "if" statement, allowing you to evaluate task parameters and direct the flow of the task accordingly. By using multiple condition blocks, you can create a nested if/switch-case structure, and get more flexibility in controlling the task flow based on various conditions.

Node Settings

Condition Block: A group of one or more conditional statements with an associated output edge.

Key, Value : The pair of parameters whose values will be compared. The key is typically used for specifying variables, and the value is usually used for specifying static values. To use a variable in the Key or Value field put {{}} double curly braces around it. For example, fill in the fields with {{key_name}} to use a variable for your key name, or with {{key_value}} for your key value. This feature helps get variable values from tasks that contain arrays or objects.

The following comparison operators are available:

== 
!= 
> 
< 
RegExp 

+ Add condition - adds a new key-value field to a condition.

+ New block - adds a new condition block with a new outgoing edge.

Ordering rules

Within a Condition node, conditions (key-value fields) within a condition block are linked together by the "&&" (AND) operator. This means that every condition must be met for the condition block to be considered true.

Multiple condition blocks within the same node are connected by the "||" (OR) operator. These condition blocks are evaluated from top to bottom, and the first block with every condition being true is followed. If none of the blocks are evaluated as true, the task follows the default output edge.

Examples

One Condition Block and One Condition

In the simplest case, the Condition node contains only one condition block with a single condition. You might use the Condition node to check whether the value of a specific parameter in a task is above or below a certain threshold. In this example, we check whether the value of the "age" parameter in the task is above 18 (see Picture 2).

Task age = 21.png

Picture 2. One condition, one condition block, the condition is met

It's important to note that if a task does not contain an "age" parameter, it will fail to meet the condition. In other words, for a condition to be considered true, it must be explicitly met by the task's parameters (see Picture 3).

Task age = 21 1.png

Picture 3. One condition, one condition block, the condition is not met

One Condition Block With Two Conditions

When using the Condition node, if a single condition block contains multiple conditions, all of them must be satisfied for the block to be considered true. For example, you might use a condition block to check whether a task's parameters meet certain criteria, such as whether the "age" parameter is above 18 and the "gender" parameter is female (see Picture 4).

Task age = 21 2.png

Picture 4. Two conditions, one condition block, both conditions are met

It's important to note that satisfying one condition within a block is not enough; all conditions must be met for the block to be true. In the example given, it is insufficient for the "age" parameter to be above 18; the "gender" parameter must also be female (see Picture 5).

Task age = 21 3.png

Picture 5. Two conditions, one condition block, one condition is not met

Two Condition Blocks

In some cases, a Condition node may have multiple condition blocks. When evaluating a task, each block is checked in order, and the first block with all its conditions met is followed (see Picture 6).

Task age = 21 4.png

Picture 6. Two condition blocks, one condition each, the first condition is met

In this example the task's parameters are evaluated against two separate condition blocks. Even though the conditions set in both blocks are met, the task will only follow the output edge of the top block, since it is the first one to be satisfied.

Getting task parameters from State Diagrams

In this node, you can access a single task parameter or a whole task stored in a State Diagram using these constructions.

Error handling & troubleshooting

When an error occurs in the node, the following fields are added to the initial task depending on the error and node type:

Error parameter nameParameter description
__conveyor_node_type_return_type_error__Error type: hardware (system error), software (error in a node logic/settings)
__conveyor_node_type_return_type_tag__Error tag
__conveyor_node_type_return_type_description__Error description in human-readable language. Can be static or dynamic
ProblemCauseSolution
Condition node is not working as expectedTypo in parameter nameParameter names are case-sensitive. For example, if the task parameter is “Phone”, but it is written as "phone" in the node, the condition node will not recognize them as being identical.
Incorrect value typeChange value type. For example, if the task value is "Count": 10 (Number), but the condition is specified as "Count"=10 (String), the comparison will always fail.
Comparing two variablesFor example, condition amount == limit will not work properly, as by default limit will be considered a string. To overcome this, you can specify that you are accessing the value of a variable by using double braces, i.e. {{limit}}.

What's Next