The Branch state allows you to add conditions to the circuit's workflow and execute tasks based on those conditions. It decides the path of execution based on input to this Branch state. This is similar to having an 'If else' or 'switch' case.
A Branch state may have more than one 'Next' state, but only one of the branch states will be executed. A branch state cannot use 'End' state.
Use Case Example: In the case of employee onboarding, after the employee details are provided, the submitted documents undergo verification. To handle appropriate action after verification, the Branch state can be employed based on the input received. If the verification status is determined as 'success', the circuit will proceed to the next pre-configured state. On the other hand, if the verification status is identified as 'failure', the circuit will follow a different path to the configured state.
Let us see how to configure the Branch state in Builder View and Code View.
Builder view
To configure a Branch state to your circuit:
-
In Builder View, drag and drop the Branch state from the left pane into your circuit or click the required branch state of the circuit.
-
-
You can include branches within this state by selecting Add Condition. This feature allows you to incorporate a state and define conditions for its execution. Upon meeting the condition for each branch, the specified subsequent state will be executed.
-
In Condition add $.verification == 'success' field set the next Success state in Go To.
-
Similarly, you can add another condition as $.verification == 'failure' and set it to a Failure state in Go To.
-
Branch state has a default pathway that you can link with the next state of the circuit. If none of the conditions is followed, the state will be executed with the default branch.
The following 'Condition' operators are supported:
Operator |
Description |
&& |
And |
== |
Boolean Equals |
!= |
Not |
== |
Numeric Equals |
> |
Numeric Greater Than |
>= |
Numeric Greater Than Or Equals |
< |
Numeric Less Than |
<= |
Numeric Less Than Or Equals |
|| |
Or |
== |
String Equals |
Code View
In Code View for Branch, each branch must have Condition and Next fields.
The JSON to configure the Branch state for the above example is:
{
"Action - Approve or Reject": {
"type": "branch",
"next": "Verified and Approved",
"branches": [
{
"condition": "$.verification == 'success'",
"next": "Verified and Approved"
},
{
"condition": "$.verification == 'failure'",
"next": "Verified and Rejected"
}
]
}
}