Function #40: Update Contact with Product details from it's Related list in Deals

Function #40: Update Contact with Product details from it's Related list in Deals



Welcome back everyone!

The last custom function showed how to update records in the Accounts module with information in records from Custom Modules . This week, let's look at a function that lets you update a Contact record's subform with Product details. The information from the records in the Products related list of Deals module is copied to the subform in the Contact record.

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 custom function:

  1. Go to Setup > Automation > Actions > Functions > Configure Function > Write your own.
  2. Provide a name for the function. For example: "Product quantity update in Deal". Add a description (optional).
  3. Copy the code given below.
  4. Click “Edit arguments”.
  5. Enter the name as “dealId” and select the value as “Deal Id”.
  6. Enter the name as “contId” and select the value as “Contact Id”.
  7. Click Save&Execute Script to check the code.
  8. Save the function.

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 code given above works only for V2 version of Zoho APIs. Please note that the code WILL NOT work for Version 1.0 APIs.

Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful. Do check out other custom functions shared in this series here .

See you all next week with another interesting custom function. Ciao!


    Access your files securely from anywhere











                            Zoho Developer Community





                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts





                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ




                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方