Knowing which products a customer account has purchased can provide valuable insights into their needs and preferences. This information can help you customize your sales and marketing efforts to serve their needs better, leading to increased customer satisfaction and loyalty. Additionally, it can help you identify cross-selling and upselling opportunities and potential areas for product or service improvements.
However, a quick glance at an account in your CRM will show that this crucial information is currently unavailable. While the Products section is present, it only displays the products manually associated with that account. How can you view the list of products an account has purchased in the past? A custom related list powered by a function can help you easily retrieve products from various quotes created for an account and display them on its details page. Continue reading to learn how to accomplish this task in less than 30 minutes.
Solution by : Andrew, Aether Automation
Permissions and availability
- Users with the Manage Extensibility permission can write custom functions.
- Users with the Modules Customization permission can add related lists.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Write a custom function using Zoho's Deluge scripting language that fetches the products from the different quotes created for an account. Learn more
- Add a related list within the account details page and include the custom function to display the products the account has purchased. Learn more
- Test the function in a sandbox environment before deploying it to your production environment. Learn more
Write a Custom Function
The first step is to write the custom function that will be linked to the related list.
- Go to Setup > Developer Space > Functions > +New Function.
- Provide a name and display name for the function. For example: "Products Purchased".
- Set the category of the function as Related List.
- Copy and paste the code provided below.
- Click Edit Arguments.
- Enter the parameter name as "id" and select the type as "string".
- Click Save.
The code
//Get the account
accountData = zoho.crm.getRecordById("Accounts",id);
//Get the quotes created for the account
listOfQuotes = zoho.crm.getRelatedRecords("Quotes","Accounts",id);
info listOfQuotes;
//Get all the products related to the quotes
productList = list();
for each quote in listOfQuotes
{
for each lineItem in quote.get("Product_Details")
{
itemObject = Collection();
//info lineItem;
productName = lineItem.get("product").get("name");
productID = lineItem.get("product").get("id");
itemObject.insert(productName);
itemObject.insert(productID);
productList.add(itemObject);
}
}
//Make the products unique
productList = productList.distinct();
info productList;
//Assemble the XML related list
responseXML = "";
responseXML = responseXML + "<records>";
rowNumber = 0;
for each productToDisplay in productList
{
rowNumber = rowNumber + 1;
responseXML = responseXML + "<row no=\"" + rowNumber + "\">";
responseXML = responseXML + "<FL val=\"ProductName\">" + productToDisplay.get(0) + "</FL>";
urlToRedirectTo = "<<INSERT ZOHO CRM PRODUCTS URL HERE>>" + productToDisplay.get(1);
responseXML = responseXML + "<FL val=\"Product Link\" link=\"true\" url=\"" + urlToRedirectTo + "\" > Link </FL>";
responseXML = responseXML + "</row>";
}
responseXML = responseXML + "</records>";
return responseXML;
Notes
- Paste the Zoho CRM Products page URL in the above code snippet—for example, https://crm.zoho.com/crm/org123456789/tab/Products/.
- Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more
- If you want more information about a purchased product, you can modify the function's code snippet to display additional fields besides the name and link.
- Newly added products or modified product fields will not be available on the new related list.
Add a related list
The final step is to add a related list to the account details page to display the list of products they've purchased.
- Open an account record to view its details.
- Go to the Related List panel on the left and click the Add Related List option.
- Select Functions in the pop-up window.
- Select Add Now, corresponding to the function you created in the previous steps.
- Specify a name for the related list. For example: "Products Purchased".
- Press # to fetch the merge field and map the argument as id = Accounts > Account Id.
- Click Save.
Tips
- Click the Reorder icon to move the Other Open Deals list to a specific location on the deal details page.
- To remove the native Products section, move it to the Unselected List.
Test the solution
- Go to the Accounts module and click on the desired account.
- On the Account Details page, look for the Products Purchased related list section. It will display the names of the account's purchased products and their links.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleAccounts
- Trigger PointRelated List
- EditionEnterprise and above
- ComplexityMedium
- Implementation Time30 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST