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:
- Go to Setup > Developer Space > Functions > + Create New Function.
- Select Automation as Function type and click Next.
- Provide a name for the function. Add a description(optional).
- Copy the code given below.
- Click Edit Arguments.
- Enter the name as dealId and select the type as Int.
- Enter the name as contId and select the type as Int.
- Click Save&Execute Script.
- 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"),""));
sub_forms.add(subform);
}
parammap = Map();
parammap.put("Product_Details",sub_forms);
update = zoho.crm.update("Contacts",contId.toLong(),parammap);
info parammap;
info update;
Note:
- 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!