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.

Getting started with the function:

  1. Go to Setup > Customization > Modules and Fields > Select the 'Contacts' module > Links and Buttons > + New Button.
  2. Provide a name for the button. For example: "Update Contact details in Deals". Add a description(optional).
  3. Choose View Page from the drop-down list.
  4. Select Writing Function from the subsequent drop-down.
  5. Provide a name for the custom function. Add a description(optional).
  6. Copy the code given below.
  7. Click Edit Arguments.
  8. Enter the name as contId and select the value as Contact Id.
  9. Save the changes.
  10. Save the button.
 

The Code:


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.
  • In Zoho CRM, the Deals module was formerly referred to as Potentials.
  • 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