You can configure the Circuit in two different ways.
Circuits are built with states using the drag-and-drop functionality in Builder View or with simple JSON construction in Code View. For every change made in Builder View, the equivalent JSON text is updated automatically in code view, and vice versa. This can be observed by changing one view and then checking out the circuit in the other.
Configuring a Circuit in Builder View
In Builder View, you can construct your circuit with the readily available states in the left pane. States are the building blocks of a circuit that can perform tasks, make decisions, or simply pass the output from one state to another.
circuit states are categorized as follows:
Flow Controls
Functional States
Bridge Controls
To explore more about the States in the Circuit, check here: States of Circuit.
Constructing a circuit in Builder View involves two steps:
Add a State
Define a State
Step 1: Add a State in Builder View
Drag and drop the state from the left pane to the visual workflow. A pop-up window will open.
Enter a unique name for the state.
Select the 'Previous State' and 'Next State' between which the new state has to be added. When you create the first state, the previous state and next state will be 'Start' and 'End' by default.
Click Create. The state will be displayed in the flow diagram.
Step 2: Define a State
Click a state in the visual workflow.
On the right pane, under Configuration, you can optionally edit the state name in the Name field.
The Type field by default displays the state type based on the state you have dropped in the builder view. You can either retain the created state type or change it in the dropdown list. In case the state type is modified in the dropdown list, the previously saved state definitions, if any, will be reset according to the state selected.
For Flow Controls, select the states from the list and configure the related fields to the state.
In the case of Functional states, select the name of the Function, Webhook, or Circuit to be associated with the state and define the error-handling options. Similarly, for Bridge controls select the name of the Bridge to be associated with the state.
Under Input / Output, configure the Paths and Parameters required for Input and Output Processing. To know more about I/O paths, click here. Click Save.
You can also change the view to horizontal, auto-arrange states in the flow diagram, and zoom in, or zoom out using the icons on the right side of the visual workflow.
Click Zoom In icon to increase the size of the circuit.
Click Zoom Out icon to shrink the circuit size.
Click Auto-arrange icon to place the circuit in the center of the page.
Click Change view icon to position the vertical circuit horizontally and vice versa.
Points to ponder
Some state types have additional parameters. For example, the Wait state contains Duration, and the Batch state includes Collection Path and Collection Variable. Similarly, the Parallel state requires Add Path, and the Branch state needs Add Condition. All states except Success and Failure have Next State. The final state of a circuit is defined by having the Next State value as 'End'.
Dynamic input parameters can be added for Function using Add Parameter and for Webhook using Add Parameter and Add Header.
Configuring a Circuit in Code View
In Code View, you can define your state machine in a simple JSON-based, structured language. Once a circuit is created, a sample workflow with the Pass state as 'State 1' is created by default. You can click the Code View in the top band to view the auto-generated JSON code of the circuit.
A state name is a JSON object, and its properties are the key-value pairs of that object. Properties like type and next are commonly used for all states. If a state does not mention the next key, it is the last state in the circuit. If a state is not referred to as next in any other state, it is the first state of the circuit.
You must follow the standard JSON syntax while coding a circuit.
Constructing a circuit in code view involves the following steps:
- States comprises attributes. Enter a state name. Define the attributes for the state as key-value pairs.
- Define the below common fields of the state
- name: All states must have a unique name to identify them within the circuit. In the above displayed circuit, 'Create User' is the name of the circuit.
- type: The actual functionality of the state is referred to by its type.
- next: The name of the next State to run after the completion of the current state. In the above circuit, 'End' is the next state for 'Create User'.
Define the unique fields of the states. Refer to the States of Circuit to explore the fields for each state. Provide the Bridge ID and configuration details for bridge controls.
Click Save.
In the event of an error in JSON definition, a red cross mark [] will be displayed beside the error line. Upon hovering on the mark, the reason for the error is displayed.