In Zoho Circuit, states are building blocks of a circuit that can perform tasks, make decisions, or simply pass the output from one state to another. You can build circuits with states using the drag and drop functionality in
Builder View, or with simple JSON construction in
Code View.
Zoho Circuit classifies states into two types
- Flow Controls
- Functional States
States in Zoho Circuit Flow Controls lets you control the flow of your circuit. For example, using a flow control state called 'Pass', you can pass your input from one state to another; using states 'Success' and 'Failure', you can stop the execution of a circuit.
Functional States helps you to execute business logic in circuits. You can achieve this by writing functions in the built-in editor, creating links for webhooks, or by associating a circuit within a circuit.
You can build your circuits with the states available in Flow Controls and Functional States. States consist of attributes. Some states are defined by using unique attributes. For example, the following is a sample circuit that consists of 'Pass' and 'Wait' state in Code View.
- {
- "Pass State": {
- "start": true,
- "type": "pass",
- "next": "Wait State"
- },
- "Wait State": {
- "type": "wait",
- "next": "End",
- "duration": 3
- }
- }
While the 'type' and 'next' fields are available in both the states, the 'wait' state consists of a unique attribute, 'duration'. Similarly, states are made up of common fields and unique fields.
Common Fields of States
Name
All the states must have a unique name to identify them within the circuit.
Type
The actual functionality of the state is referred in its type. The following types are supported:
- Pass
- Branch
- Parallel
- Wait
- Batch
- Success
- Failure
- Function
- Webhook
- Circuit
Next
The name of the next state that has to be run after the completion of the current state is denoted using 'Next'. Except for the terminal states 'Success' and 'Failure', all the other states must have this field. The last state of a circuit must have 'End' as the value of its 'Next' field.
Start
Every circuit must have any one state with field value 'start: true'. Although states can be defined in any sequence, the order of execution depends on the 'start' and 'next' field. Hence, 'start' field has to be provided for the beginning state. However, only one state within a circuit is allowed to have this field value.
Apart from the common fields, states also share certain fields, such as Input Path, Output Path, and Result Path for Input and Output handling.
Note: All fields and their values are case-sensitive. Once a value is defined, the exact value must be inputted throughout the circuit.
Flow Controls
As the name suggests, Flow Controls aids you in controlling the course of direction of your circuit.
Flow Controls consists of the following states:
- Pass - Transfers the input from one state to another
- Branch - Decides between branches of execution based on input
- Parallel - Performs simultaneous executions
- Wait - Inserts a delay for a specific time
- Batch - Implements multiple group executions
- Success - Terminate an execution returning Success
- Failure - Terminates an execution returning Failure
Pass
The Pass state passes its input from one state to another without performing any task. You can also use this state to inject data or modify the input data in your circuit.To input data in Builder View, click the corresponding state, then select 'Input/Output'. Enter the key(in format '$.fieldname') in 'ResultPath' and the value within 'Result'.
Similarly, in Code View you can directly add the parameters 'resultPath' and 'result' within the state. Pass state example: "next": "Update Job Details",
"resultPath": "$.Jobdetails.Id",
For example, if the input to this pass state is:
- {
- "Agent": "Saira",
- "Jobdetails":{
- "Issue": "Access failure",
- "Location": "CA"
- },
- "JobName": "JLP112"
- }
Then, the output would be:
- {
- "Agent":"Saira",
- "Jobdetails":{
- "Issue":"Access failure",
- "Id":112,
- "Location":"CA"
- },
- "JobName":"JLP112"
- }
Branch
Add a state that can pass your input to a different state based on its value. This is similar to having an 'If else' or 'switch case'. In Builder View, you can define branches by selecting Add Condition.Add Condition allows you to set the rule for the respective branch using 'Condition' and select the next state using 'Go To'.
The following 'Condition' operators are supported:
Operator
| Description
|
&&
| And
|
==
| BooleanEquals
|
!=
| Not
|
==
| NumericEquals
|
>
| NumericGreaterThan
|
>=
| NumericGreaterThanEquals
|
<
| NumericLessThan
|
<=
| NumericLessThanEquals
|
||
| Or
|
==
| StringEquals
|
In Code View for Branch, each branch must have 'Condition' and 'Next' fields. Branch state example:
- "Add User Details": {
- "type": "branch",
- "next": "End",
- "branches": [
- {
- "condition": "$.value1 == 'new'",
- "next": "Add User"
- },
- {
- "condition": "$.value2 == 'available'",
- "next": "Update User"
- }
- ]
- }
Parallel
Perform simultaneous executions using Parallel. For example, consider a scenario where you need to send an email and add requests in JIRA and Zoho Projects whenever a new ticket is raised. You can do all the three independently and simultaneously without waiting for one another using Parallel.
In
Builder View, define parallel executions using 'Add Path'.
In 'Add Path', provide a unique name for the path using 'Name' and the state that needs to act as the root or starting point for the path using 'Start At'. Similarly, in Code View, along with the common fields, the paths are also defined with their unique name and root.
- "Customer Details": {
- "type": "parallel",
- "next": "End",
- "paths": [
- {
- "name": "Path1",
- "root": "Check Address"
- },
- {
- "name": "Path2",
- "root": "Check Phone"
- }
- ]
- }
Wait
A 'Wait' state inserts a specific delay into your circuit. In Builder View, you can define the wait period under 'Duration' in seconds.
Similarly, in
Code View, you can add the wait time under the 'duration' field.
Wait state example:
- "wait_five_seconds": {
- "type": "wait",
- "next": "SelectUsers",
- "duration": 5
- }
Batch
'Batch' state allows you to perform simultaneous group executions as batches.
A 'Batch' state contains the following configuration in
Builder ViewCollection Path - Enter the key that contains the values to be processed by 'Batch' state in the input JSON.
Collection Variable - Provide any variable name. The values within the collection path will be operated on, using this name.
Bind Type - You can bind the batch state to a function, webhook, or circuit using 'Bind Type'.
Next State - Enter the state name to which the output of this state needs to be traversed.
No. of Jobs - Define the number of threads for the batch state.
In Code View, JSON details can be provided under fields 'collectionPath' and 'collectionVariable'. You can link a function, webhook or circuit using 'bind' and define the number of threads for batch using 'degree'. - "New Job": {
- "type": "batch",
- "next": "End",
- "collectionPath": "$.batchJob",
- "collectionVariable": "jobDetails",
- "bind": {
- "type": "function",
- "functionName": "new_dlgfn"
- },
- "degree": 5
- }
Success
A 'Success' state can be used to terminate an execution. It comes handy when using a 'branch' state that don't do anything except to finish the circuit.
Since Success states are end states, they don't have a 'Next' state, and don't require an 'End' field.
Success state example:
- "Complete Circuit": {
- "type": "success"
- }
Failure
A 'Failure' state stops an execution of the circuit, marking it as failure. You can add a specific 'Error Message' and 'Reason' to help in debugging.
The equivalent fields added in
Code View for adding failure details are 'errorMessage' and 'reason'.
Failure state example:
- "New State 14": {
- "type": "failure",
- "errorMessage": "Invalid Input",
- "reason": "ErrorCode:348"
- }