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 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:
To explore more about the States in the Circuit, check out 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 them from the left pane onto the visual workflow. This action prompts a pop-up window to appear.
Enter a unique name for the state.
Select the Previous State and Next State between which the new state needs 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.
In the right pane, under Configuration, you have the option to edit the state name in the Name field.
By default, the Type field displays the state type based on the state you have dropped in Builder View. You can either retain the created state type or change it in the dropdown list. If 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 to define the error-handling option
Click Save.
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, Parallel state requires Add Path and Branch state needs Add Condition. All states except Success and Failure have the 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 icon in the top right 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.
Click the Code View icon in the Builder View page to switch to the code editor, where you can build your circuit using JSON.
Constructing a circuit in code view involves the following steps:
States are made up of 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 the Circuit to explore the fields for each state.
Provide error handling options using the onError attribute for state types Function, Webhook, and Circuit.
Provide the Bridge ID and configuration details for Bridge controls.
Specify the inputPath, outputPath, and resultPath for Input and Output processing.
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 will be displayed.