Automatically update field details from Contacts in Deals right at the creation stage.

Business scenario:

The Deals module in Zoho CRM helps keep track of all your business opportunities. To ensure proper lead qualification process with all specifics, it is recommended to first create a lead, convert it into a contact, and simultaneously create and associate a deal with the contact. This when done with field mapping, helps retain all mapped details from the lead record to contact record and subsequently to the deal record.

However, not all businesses require creating a deal while converting the lead to a contact. Moreover, deal creation might come at a much later stage in some organizations. There is an inconvenience associated with this approach. While the deal gets associated with the contact record, all other details updated in the leads/contacts record doesn’t get updated in the deal record. Updating them manually defeats the purpose. In comes this week's custom function to the rescue. Add a button linked to this custom function in your Contacts module and update relevant details from the contact records inside the deal records in a jiffy. Use this custom function to automatically update the fields listed below from contact records to deal records:

  • Contact Name
  • Account Name
  • Title
  • Email
  • Phone
  • Mobile
  • Lead Source
  • Email Opt Out
  • Website
  • Address Information
  • Description
  • Related activities

Before proceeding, ensure that you create the relevant custom fields in Deals module.

The scope of this custom function can be enhanced even further. Depending on your line of business, you might have certain permutations and combinations possible in your customer deals. Take, for example, the case of an automobile dealer. Say there are 3 variants of a particular car model with 4 different colors and various accessories options. Instead of updating these details manually, write a custom function for each of these combinations and associate that with a button. If a customer wants a specific combination that includes model, color, and enhancements, press the corresponding button and get the relevant fields updated. The code for this week doesn't include these scenarios. This is just to highlight the power of possibilities with custom functions.

Having to create multiple custom buttons might be a little time-consuming, but it's a one-time process and the benefits are worth the effort.

Pre-requisites

  • Create and link the button with the custom function as detailed in the "Getting started with the custom function" section below.
  • To use this custom function for multiple campaigns, clone this custom function and link it with new buttons. Ensure you update the campaign id's accordingly.
  • To link multiple lead records to a campaign, just select the leads from the list view of Leads module and click on the respective campaign button.

Getting started with the function:

  1. Go to Setup > Customization > Modules > Deals > Links and buttons > Create new button.
  2. Provide a name for the button. For example: "[The deal name]". Add a description(optional).
  3. Select the placement of the button as View page.
  4. Select the action to be performed as "Writing function".
  5. Copy the code given below.
  6. Click "Edit arguments".
  7. Enter the name as "contId" and select the value as "Contact Id".
  8. Click Save & Execute Script.
  9. Save the changes.
  10. Select the profiles who can view this button.
  11. Click Save.

The code:

For v2 Editor - DRE:



contDetails = zoho.crm.getRecordById("Contacts", input.contId.toLong());
mp=map();
mp.put("Deal_Name",ifnull(contDetails.get("Full_Name"),""));
mp.put("Owner",ifnull(contDetails.get("Owner"),"").get("id"));
mp.put("Contact_Name",input.contId);
mp.put("Account_Name",ifnull(contDetails.get("Account_Name"),"").get("id"));
mp.put("Title",ifnull(contDetails.get("Title"),""));
mp.put("Email",ifnull(contDetails.get("Email"),""));
mp.put("Phone",ifnull(contDetails.get("Phone"),""));
mp.put("Mobile",ifnull(contDetails.get("Mobile"),""));
mp.put("Lead_Source",ifnull(contDetails.get("Lead_Source"),""));
mp.put("Email_Opt_Out",ifnull(contDetails.get("Email_Opt_Out"),""));
mp.put("Website",ifnull(contDetails.get("Website"),""));
mp.put("Mailing_Street",ifnull(contDetails.get("Mailing_Street"),""));
mp.put("Mailing_City",ifnull(contDetails.get("Mailing_City"),""));
mp.put("Mailing_State",ifnull(contDetails.get("Mailing_State"),""));
mp.put("Mailing_Zip",ifnull(contDetails.get("Mailing_Zip"),""));
mp.put("Mailing_Country",ifnull(contDetails.get("Mailing_Country"),""));
mp.put("Description",ifnull(contDetails.get("Description"),""));
create = zoho.crm.create("Deals", mp);
info create;
TaskDetails = zoho.crm.getRelatedRecords("Tasks","Contacts", input.contId.toLong());
for each task in TaskDetails
{
taskmap = Map();
taskmap.put("What_Id",create.get("id"));
taskmap.put("$se_module","Deals");
updatetask = zoho.crm.update("Tasks",task.get("id"),taskmap);
info updatetask;
}
EventDetails = zoho.crm.getRelatedRecords("Events","Contacts", input.contId.toLong());
for each events in EventDetails
{
eventmap = Map();
eventmap.put("What_Id",create.get("id"));
eventmap.put("$se_module","Deals");
updateevent = zoho.crm.update("Events",events.get("id"),eventmap);
info updateevent;
}
CallDetails = zoho.crm.getRelatedRecords("Calls","Contacts", input.contId.toLong());
for each call in CallDetails
{
callmap = Map();
callmap.put("What_Id",create.get("id"));
callmap.put("$se_module","Deals");
updatecall = zoho.crm.update("Calls",call.get("id"),callmap);
info updatecall;
}
return "Success";

Note:

  • Create multiple buttons to contain multiple scenarios of deals, and save the time to create a deal with the particular information.
  • This custom function works only when you create a deal using the linked button.

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