Update Contact with Product details from it's Related list in Deals

Business scenario:

A typical business process flows like this: Leads -> Contacts -> Accounts -> Deals -> Contacts. If you're wondering why 'Contacts' is mentioned twice, it is to register the deal information and associate it with the Contact. Further, this paves the road for future deals. Similarly, a deal involves procurement or giving out services or products. As such, until the deal is completed both on paper and in actuality, there is a need to keep an inventory of the number of Products involved in each deal. This is done in the "Products" module.

You can have a subform (a form within a form) in the Contact record, which contains details of Products and Services procured by the customer. And if the customer buys your product at two different timelines (say 1-2 years apart), that information also needs to be given importance and registered.

The function for this week takes care of replicating the Product details in the Contact record's subform. The Deals module has a Related list for Products, listing the details of the products involved in the deal. Once a deal is closed (won), you can set this function up to replicate the details of the product in the subform of the Contact's record (customer's record).


Getting started with the function:

  1. Go to Setup > Developer Space > Functions > + Create New Function.
  2. Select Automation as Function type and click Next.
  3. Provide a name for the function. Add a description(optional).
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as dealId and select the type as Int.
  7. Enter the name as contId and select the type as Int.
  8. Click Save&Execute Script.
  9. Click Save.

The Code:

RelatedProducts = zoho.crm.getRelatedRecords("Products", "Deals",input.dealId.toLong());
Details = zoho.crm.getRecordById("Contacts", contId.toLong());
sub_forms = List();
for each product in RelatedProducts
subform = Map();
subform.put("Product_Lookup", ifnull(product.get("id"),""));
subform.put("Product_Code", ifnull(product.get("Product_Code"),""));
subform.put("Product_Name", ifnull(product.get("Product_Name"),""));
parammap = Map();
update = zoho.crm.update("Contacts",contId.toLong(),parammap);
info parammap;
info update;


  • The above code works only for API V2.0 and not the previous version.

Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips