Update information between two modules via Lookup fields
Quotes are binding agreements between a customer and a vendor, to deliver the requested products to the customer within a specified time-frame at a predefined price. Your customers can place orders within a stipulated period (validity date) that has been mentioned in the quote, otherwise you may cancel or extend the time-frame by sending a new quote. In general, a Quote contains the Quote Number, Date, Line Items(Products) inclusive of quantity and prices based on your Price Books, Terms & Conditions and Description.
And incidently, the quote can be sent to a specific Contact or an Account. Depending on the scenario, the information to be on the quote may differ. For instance, you may want to add the Contact Phone number, Email address, Description or any information in a custom field to the quote. The Quotes module indeed has a lookup field for Contact, Deal and Account. Meaning, the information from a Contact, Deal or an Account can be copied automatically to a Quote through the lookup. So where does this custom function fit in?
It's for the information fields which are not available in a Quote. Information which is not normally available to be stored in the CRM can be stored using a custom field. Similarly, the modules Quotes, Invoice and modules like that have to be updated to store that additional information too. Are you going to juggle between modules to copy each additional information when a lookup is already available?
This custom function latches on to the Lookup field and whenever a Contact is selected as a lookup, the custom fields specified in the custom function are also transferred automatically. Furthermore, this custom function is not limited to the Quotes module. You can use this function to any module that has a Lookup field.
Getting started with the function:
- Go to Setup > Automation > Actions > Functions > Configure Function > Write your own.
- Provide a name for the function. For example: “Auto-populate deal amount”. Add a description(optional).
- Choose the module as Deals.
- Copy the code given below.
- Click Edit Arguments.
- Enter the name as quoteId and select the value as Quote Id.
- Enter the name as contId and select the value as Contact Id.
- Save the changes.
contDetails = zoho.crm.getRecordById("Contacts", input.contId.toLong()); mp=map(); mp.put("First_Name",ifnull(contDetails.get("First_Name"),"")); mp.put("Last_Name",ifnull(contDetails.get("Last_Name"),"")); mp.put("Broker_First_Name",ifnull(contDetails.get("Broker_First_Name"),"")); mp.put("Broker_Last_Name",ifnull(contDetails.get("Broker_Last_Name"),"")); mp.put("Property_Street",ifnull(contDetails.get("Property_Street"),"")); mp.put("Property_City",ifnull(contDetails.get("Property_City"),"")); mp.put("Property_State",ifnull(contDetails.get("Property_State"),"")); mp.put("Property_Zip",ifnull(contDetails.get("Property_Zip"),"")); updateResp= zoho.crm.update("Quotes",input.quoteId.toLong(), mp); info mp; info updateResp;
Adding to the workflow
- Go to Setup > Automation > Workflow Rules.
- Click '+ Create Rule'.
- Select the Module for which this custom function has to be added and give it a name and a description(optional).
- Select "Create or Edit" under "On a record action", in the "When do you want to execute this rule?".
- Select the Condition as "All Records" and click Next.
- Choose "Function" from Instant Actions.
- Select the option "Function" (Created by users from your organization).
- Select the required custom function and click Publish.
- Provide a Description for the custom function and Publish it.
- Save the workflow.
- You can use the code on any module. Change the name of the module from 'Quotes' to whichever module you prefer and update the code accordingly.
- The Fields in the left section (right after mp.put) of the code are the destination fields and the ones in the right are the source fields. Update your code according to your requirement and your fields.
- If there is a need to copy information from a custom field, you need to create that custom field for the destination module too.
- 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!