Conditions

Flows are perfect for decision making.

Say we are implementing a KYC pipeline flow, and one of the states is a credit check state, and based on its outcome we need to decide whether to approve a customer, or deny them.

In order to make that decision, we need a 'Condition State', which essentially allows us to define simple and complex "If" conditions (either by the UI configuration, or by custom scripting).

Defining a condition state is as simple as drag-and-drop* the "New Condition" box from the editor menu:

*it is also possible to just click on 'New Condition' if you don't like to drag-and-drop

Now, let's take a look at the condition's state configuration.

Condition State Configuration

A condition state consists of 3 entities:

  1. A condition "logic" - the actual "if" statement

  2. A condition "group" - which can contain multiple condition logics or even other condition groups

  3. A Relationship - can be one of the two: "AND" or "OR". The relationship exists between all the entities of a Condition Group.

Condition Logic

A condition logic defines a statement, which consists of 3 parts:

SOURCE(actual) ACTION TARGET(expected).

So if our state "credit" executed with a result of "425", and in our condition we check if the score is larger than "500", then the statement would look like this:

SOURCE(425) ACTION(Larger Than) TARGET(500)

425 > 500

This statement is NOT correct (false), and so the Condition's state execution would fail, and all states that are connected to the Condition state via its "Failure Out Port" would be invoked.

This is how a Condition Logic (Statement) wizard looks like:

So we have chosen the source as the "State Output" of the state named "root" (specifically, we want the ".entryPoint" value from the output of the "root" state).

The action here is equals (larger than equals)

And the Target (expected value) is 42.

You can add multiple statements to the same Condition Group using the "Add Condition" button.

Adding more than one condition to a certain group will allow you to choose the relationship between all the items in that group:

Relationship between items

If you choose "AND", then ALL the statements/nested groups in this group must succeed in order for the group to succeed. If even one of the statements or nested groups fails, then the whole group will fail.

For "OR", it is sufficient for just one condition in the group to succeed.

Nested Groups

Every group can contain either statements or other groups. This allows you to define complex conditions that have multiple groups:

Nested Groups

The relationship functionality can be defined between all items of a group, whether those items are statements, or nested groups.

Accessing entryPayload in a condition

You may want to define the condition based on the entryPayload sent for the current execution. This is possible by simply using the state output of state "root", which will just return verbatim everything supplied as entry payload.

Code in condition

If your condition requires a more complex definition, use the "Code" tab in the Source definition, and a code editor will appear!

Code in condition

You can write any code (including using external libraries) which will be used to determine the output of this specific condition.

If your code returns "true" - the condition will be considered to be met.

If it returns "false" or raises an exception - the condition will be considered to be unmet.

Conditions will be evaluated inside-out (from the deepest outwards).

As a teaser, just remember that during execution time, every entity in this view will light up in either green or red, in order to indicate which conditions (or groups) were met, and which weren't. So when you are debugging issues, you will be able to see exactly which "if" happened, and why. Boom.

See how conditions behaved, inside out