Hello everyone!
We are back with yet another post on Circuits in Zoho CRM.
In our last week's post, we discussed a use case, the various states and functions involved in that circuit, testing and execution, and associating that circuit with a workflow.
In today's post, we will see how we can associate that circuit with a button and a blueprint, the output format of the "Zoho CRM" functional states, and a few FAQs.
Use case recap
Consider that we have a module in CRM called Customers, where we have personal info of customers, tax-related details, tax and personal ID verification details and status. Our aim is to check the loan amount, check eligibility, and then grant or reject it.
Our condition is that whenever the loan amount is less than Rs. 500,000, the circuit should directly proceed to document verification. When the requested loan amount is greater than Rs. 500,000, we must check a few eligibility criteria before proceeding to document verification.
This is the circuit for the above use case.
Let us see how this circuit works with a button.
Associating the Circuit with a Button
Follow the steps in this article to create a button in the Customers module.
Choose "Execute Circuit" from the list of Custom Actions for the button.
From the list of Circuits, choose the Verification Process circuit.
Here is the execution of the circuit when you execute the button action.
Associating the Circuit with a Blueprint
Our blueprint would look like this.
Specify the entry criteria as Amount > 500000.
When the amount > 500000, and tax is filed, the "After" transition would be executing the circuit as shown in the image.
When the tax is not filed, the "After" transition will still be executing the circuit.
Execution Logs
Go to Setup > Developer Hub > Circuits.
Click the Execution Logs tab. You can see the list of circuits that were executed with their duration, start and end times, the place where they were triggered from, and the status.
When you click any of the entries, you can see the execution of the circuit.
If a circuit's execution failed, the status would be Failed.
When you hover over the entry, you can see Retry and Rerun options.
Retry executes the circuit from the state where it failed, while Rerun executes the circuit from the beginning.
Output format of the "Zoho CRM" Functional States
After the input is processed by the state, the output will be available as a JSON. Result Path selects(using JSON Path format) what combination of the state result and the actual state input has to be passed to the output, from that JSON.
Each JSON of the Zoho CRM state will have two objects viz., ZohoCRM and the variable you have specified in the Result Path for that state(depicted in the following image).
Here is the JSON.
{ "ZohoCRM": { "record_id": "{recordid}", "user_id": "{userid}", "module": { "api_name": "{moduleapiname}", "tab_label": "{modulelabel}", "id": "{moduleid}" } }, "{name}": {} //contains state result } |
The various Zoho CRM states and their sample JSON formats in the response are discussed in this section.
- The Get User state returns the Get user API response.
- The Get Variables state returns the CRM variables in your org.
- The Get Org state returns the org details.
- The Get Record state returns the record's details.
1. Get User
{ "ZohoCRM": { "record_id": "5575270000005762031", "user_id": "5575270000005379053", "module": { "api_name": "Customers", "tab_label": "Customers", "id": "5575270000001975002" } }, "get_user": {//This is the name specified for the Result Path "users": [ {.. Get a user API response.. } ] } } |
2. Get Variables
{ "ZohoCRM": { "record_id": "5575270000005762031", "user_id": "5575270000005379053", "module": { "api_name": "Customers", "tab_label": "Customers", "id": "5575270000001975002" } }, "get_var": {//This is the name specified for the Result Path "variables": [ {.. Get Variables API response.. } ] } } |
3. Get Org
{ "ZohoCRM": { "record_id": "5575270000005762031", "user_id": "5575270000005379053", "module": { "api_name": "Customers", "tab_label": "Customers", "id": "5575270000001975002" } }, "get_org": {//This is the name specified for the Result Path "org": [ {.. Get Organization API response.. } ] } } |
4. Get Record
{ "ZohoCRM": { "record_id": "5575270000005762031", "user_id": "5575270000005379053", "module": { "api_name": "Customers", "tab_label": "Customers", "id": "5575270000001975002" } }, "record": {//This is the name specified for the Result Path "data": [ {.. Get records API response.. } ] } } |
The following table gives you an idea of how the response for the Get record state is depending on where the circuit is triggered from.
Trigger | Applicable? | Output |
Workflow | Yes | data[0] (Respective record) |
Blueprint | Yes | data[0] |
Button - Details Page | Yes | data[0] |
Button - Edit Page | Yes, but the current edited value won't be considered | data[0] |
Button - Each Record | Yes | data[0] |
Button - Mass Action | Yes, the Execution preview will be redirected to the Circuit's Execution tab | data[0] |
Button - Related List Selection* | The related module's record, not the base module's record | data[0] |
Button - Create Page | No | {} |
Button - Clone Page | No | {} |
Button - Utility Menu | No | The circuit fails because `record_ids` will be passed as an array instead of `record_id` |
FAQs
1. Is it possible to trigger a Circuit via a REST API?
It is not possible to trigger/execute a Circuit via REST API as of now. We have plans to support that in the future.
2. How to pass record details/Is it possible to send parameter values to a Circuit while starting the execution?
You can simply use the "Get Record" state to get the details of a record, and the response will be the same as that of the Get Records API.
3. What API version is 'Get Record' using?
Version 2 of CRM APIs.
4. Is it possible to return JSON as a response from the Function state?
Yes. To send a custom JSON response, you should use `crmAPIRequest` as the key and the value as the API response in Functions.
Example:
// This is the actual content you will get in the Circuit. output = {"name":"Zylker","zipcode":600001}; // This is to construct the crmAPIResponse response = Map(); response.put("status_code",200); response.put("body",{"code":"success","details":{"output":output,"output_type":"string","id":"896753000000146001"},"message":"function executed successfully"}); return {"crmAPIResponse": response}; |
5. Is it possible to pause the circuit and continue to the next state on demand/on trigger from a remote server (via REST API)?
It's not possible to pause the state and trigger the next state from a remote server. As a workaround, you can use the "wait" state (up to 30 days i.e 25,92,000 seconds) is and fetch the status periodically to move to the next state upon the desired response received.
6. Is it possible to retry Circuit execution from the failed state?
Yes, one can retry the Circuit execution from the last failed state or can rerun the entire execution from the beginning. These options are available for every Failed execution under the Execution Logs.
7. How are credits calculated for a Circuit?
Circuits use an edition-based credit system, where each transition in the circuit consumes one credit. While every edition has a maximum credit limit, you can always purchase add-on credits from the Credits tab on the Circuits dashboard. Refer to this help page for details.
We hope you found this post useful. Let us know your comments in the Comment section.
Cheers!
Shylaja
Additional Reading: