Each business requires a mutual integration between its individual components in order to operate efficiently.Zoho CRM is a complete enterprise setup, with all its modules mutually linked with each other to keep your data up to date. The Related List is one of the mainZoho CRM features that help to maintain synchronized data. The Related Lists are records associated with the parent record. When the data in a single module in your Zoho CRM account is updated, it is also linked as a related list with the associated modules.
For example, let's say a new contact is created and associated with an existing account. This contact will now be linked to the "Contacts" section (related list) of the account to which it was associated in the "Accounts" module.
In this post, we'll look at ZOHO.CRM.API.getRelatedRecords() JS SDK in detail. Given the association between the different modules in Zoho CRM, it is possible for us to fetch the related list data from a given module through widgets using an API.
ZOHO.CRM.API.getRelatedRecords() is used to fetch the related list details of a given module from a widget.
Here config is the configuration object constructed with the following details:
API Name of the module.
RecordID of the entity whose associated details are required.
API Name of the relatedList of the entity.
optional, To get the list of related records from the respective page.
optional, To get the list of related records available per page.
Here, the Contacts that are associated with the account with account ID "4440879000000423000" of the "Accounts" module is fetched with up to 200 records from page 1.
Let's take a simple scenario where you want to know the total profit of a particular account, obtained from the deals associated with it to set up a finance-related managerial operation. We can use ZOHO.CRM.API.getRelatedRecords(config) in a widget to retrieve all the deal-related details of a particular account in the "Closed Won" stage. Let's see how this can be implemented in a widget:
// Event Listener triggered when the entity page is loaded
var id = data.EntityId;
// Fetch the 'Deals' related list details of the Accounts module
//Looping through every deal
for (i = 0; i < rec.length; i++)
//Fetching the amount field value of the deals
amt = rec[i].Amount;
//Summing the value in the amount field of every deal in "Closed Won" stage to retrieve the total revenue
//If the user chooses the 'Yes' option to update the total revenue
//Updates the annual revenue field value with the calculated total amount
//closes the widget window
//If the user chooses the 'No' option to update the total revenue
//closes the widget window
//Initialize the widget
There are a few Zoho CRM APIs that are used in the above code snippet to perform the specified functionality. Let's have a look at those:
ZOHO.embeddedApp.on("PageLoad",function(data)) - An event listener that is triggered whenever an entity Page is loaded. Here, when a particular account is selected from the list of accounts available in the "Accounts" module, the event listener is triggered on PageLoad from which the ID details of that particular account can be retrieved.
ZOHO.CRM.API.getRelatedRecords(config) - The retrieved ID is then passed as the Record ID input of the getRelatedRecords Zoho CRM API along with the other required details. The entity here is Accounts and the related list is Deals to retrieve account related deals. This will fetch all the deals associated with that particular account. Using the details obtained, you can go ahead and calculate the total revenue/profit by summing up the amount of the deals in "Closed Won"stage.
ZOHO.CRM.API.updateRecord(config) - The total calculated revenue is then updated to a field in the "Accounts" module using the updateRecord Zoho CRM API.
We have used ZOHO.CRM.UI.Popup.close() in our example to close the widget popup after the user decides to choose either "Yes"or "No"to update the total revenue.
In a similar way, you can use the ZOHO.CRM.API.getRelatedRecords(config) API to obtain the related list details of modules from a widget and make operations as per your business requirement.
We hope you found this information useful. Keep following this space for more insights on how to get the most out of your Zoho experience.