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.


  • 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());
create = zoho.crm.create("Deals", mp);
info create;
TaskDetails = zoho.crm.getRelatedRecords("Tasks","Contacts", input.contId.toLong());
for each task in TaskDetails
taskmap = Map();
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();
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();
updatecall = zoho.crm.update("Calls",call.get("id"),callmap);
info updatecall;
return "Success";


  • 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