Function-22: Automatically update field details from Contacts in Deals right at the creation stage

Function-22: Automatically update field details from Contacts in Deals right at the creation stage




Welcome back, everyone!

Last week, we learned how to update all member accounts simultaneously when the parent account is updated. This week, let's look at a custom function that helps you update the relevant details from contact records in deal records at the click of a button.

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

  • Go to Setup > Customization > Modules and Fields > Select the 'Contacts' module > Links and Buttons > +Create new button.
  • Provide a name for the button. For example: “[The deal name]”. Add a description(optional).
  • Choose View page from the drop-down list.
  • Select Writing custom function from the subsequent drop-down.
  • Provide a name for the custom function. Add a description(optional).
  • Click “Free flow scripting”.
  • Copy the code given below.
  • Click “Edit arguments”.
  • Enter the name as “contId” and select the value as “Contact Id”.
  • Save the changes.

Note:
  • In Zoho CRM, the Deals module was formerly referred to as Potentials.

The script:

Code for Version 2.0 API:
 
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";

Code for Version 1.0 API:

contactIdStr = input.contId.toString();
contDetails = zoho.crm.getRecordById("Contacts", input.contId.toLong());
name = ifnull(contDetails.get("First Name"),"")+ " " + ifnull(contDetails.get("Last Name"),"");
mp=map();
mp.put("Potential Name",name);
mp.put("SMOWNERID",ifnull(contDetails.get("SMOWNERID"),""));
mp.put("CONTACTID",input,contId);
mp.put("Account Name",ifnull(contDetails.get("Account Name"),""));
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("Potentials", mp);
info create;
newpotId = create.get("Id");
TaskDetails = zoho.crm.getRelatedRecords("Tasks","Contacts", contactIdStr);
for each ele in TaskDetails
{
TaskId=ele.get("ACTIVITYID");
taskMap=map();
taskMap.put("SEID",newpotId);
taskMap.put("SEMODULE","Potentials");
UpdateTask = zoho.crm.updateRecord("Tasks",TaskId,taskMap);
info UpdateTask;
info taskMap;
}
EventDetails = zoho.crm.getRelatedRecords("Events","Contacts", contactIdStr);
for each ele in EventDetails
{
eventId=ele.get("ACTIVITYID");
eventMap=map();
eventMap.put("SEID",newpotId);
eventMap.put("SEMODULE","Potentials");
UpdateEvent = zoho.crm.updateRecord("Events",eventId,eventMap);
info UpdateEvent;
info eventMap;
}
CallDetails = zoho.crm.getRelatedRecords("Calls","Contacts", contactIdStr);
for each ele in CallDetails
{
callId=ele.get("ACTIVITYID");
callMap=map();
callMap.put("SEID",newpotId);
callMap.put("SEMODULE","Potentials");
UpdateCall = zoho.crm.updateRecord("Calls",callId,callMap);
info UpdateCall;
info callMap;
}
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 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.

I'm sure you would have planned your year-end celebrations already. We'd be back in Jan '18 with the next custom function. Merry Christmas and a Happy New Year. See you!

Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.

    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



                                                            • Sticky Posts

                                                            • Zoho CRM Functions 53: Automatically name your Deals during lead conversion.

                                                              Welcome back everyone! Last week's function was about automatically updating the recent Event date in the Accounts module. This week, it's going to be about automatically giving a custom Deal name whenever a lead is converted. Business scenario Deals are the most important records in CRM. After successful prospecting, the sales cycle is followed by deal creation, follow-up, and its subsequent closure. Being a critical function of your sales cycle, it's good to follow certain best practices. One such
                                                            • User Tips: Auto-Create Opportunity/Deal upon Quote Save (PART 1)

                                                              Problem: We use quotes which convert to sales orders but Users / Sales Reps do not create opportunities / deals and go straight to creating a quote. This leads to poor reporting. Implementing this solution improves reporting and makes it easier for users.
                                                            • Custom Function : Automatically send the Quote to the related contact

                                                              Scenario: Automatically send the Quote to the related contact.  We create Quotes for customers regularly and when we want to send the quote to the customer, we have to send it manually. We can automate this, using Custom Functions. Based on a criteria, you can trigger a workflow rule and the custom function associated to the rule and automatically send the quote to customer through an email. Please note that the quote will be sent as an inline email content and not as a PDF attachment. Please follow
                                                            • Function #50: Schedule Calls to records

                                                              Welcome back everyone! Last week's function was about changing ownership of multiple records concurrently. This week, it's going to be about scheduling calls for records in various modules. Business scenario Calls are an integral part of most sales routines.. Sales, Management, Support, all the branches of the business structure would work in cohesion only through calls. You could say they are akin to engine oil, which is required by the engine to make all of it's components function perfectly. CRM
                                                            • Function #37: Create a Purchase Order from a Quote

                                                              Welcome back everyone! Last week, we learnt how to calculate the total number of activities for a lead and further take note of the activity count for particular dates. For instance, from the period of Demo to Negotiation. This week, let's look at a function that lets you create a Purchase Order instantly from a Quote. Business scenario: In any form of business, one of the most important things to do is to document the transactions. Naturally, negotiation, signing an agreement, placing an order,


                                                            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


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • Power of Automation::Streamline log hours to work hours upon task completion.

                                                                                                              Hello Everyone, A Custom Function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as to when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it. Requirement:-
                                                                                                            • Is CRM On Premise available

                                                                                                              Hi Zoho team, Can you please let me know that CRM Zoho is available for On Premise as well? Thanks, Devashish
                                                                                                            • Last activity time is acting like last modified time

                                                                                                              When i edit the description or any field in the potential, account, contact and lead, the Last Activity Time is being updated like the Modified Time. This is messing all workflows and reports and we are unable to track real last time of activities like
                                                                                                            • CRM : Function to add user name to text field

                                                                                                              I have a lookup field in a module that is linked to the CRM users so we can assign a Project Lead to the customer. Sadly Zoho Marketing Automation doesn't sync Lookup fields so I need to extract information from the lookup to text fields: Lookup field
                                                                                                            • Zoho CRM - Restrict Login based on work hours

                                                                                                              Hi there, I'm wondering if we can restrict users to login during works - For example the users would be able to login from 8am to 5pm. I have seen the IP address restriction - the only downfall is what if the customer has dynamic IP. thanks Jiri
                                                                                                            • Tips and Tricks #46: Customize themes and templates using Show's Master View

                                                                                                              Hi All!  Let's say you want to revamp your presentation and make changes to its visual design. You can do this easily using the Master Slide and its associated layouts. The Master Slide stores information about all the layouts used in the presentation.
                                                                                                            • Currency abbreviations

                                                                                                              Hello, Im stuck, and need help. I need the currency fields for example, opportunity value, or total revenue, to be abbreviated, lets say for 1,000 - 1K, 1,000,000 - 1M, and so on, how should I do this?
                                                                                                            • Sheet View in CRM portal

                                                                                                              Hi, When will it be possible for my CRM portal users to edit/add records with Sheet View? George
                                                                                                            • What's New in Zoho Invoice | July - September 2025

                                                                                                              Hello everyone! We’re back with the latest updates and enhancements we’ve rolled out in Zoho Invoice from July to September 2025. Here’s what’s new this quarter: Introducing the Singapore Edition in Zoho Invoice Share Invoices through WhatsApp GST 2.0
                                                                                                            • Alert: Audio Call Support to be discontinued for Old Live Chat Widget from December 31, 2025

                                                                                                              Action Required: Upgrade to the New SalesIQ Live Chat Widget We're reaching out with an important update regarding the SalesIQ Live Chat Widget that requires your immediate attention. Effective December 31, 2025, audio call functionality will no longer
                                                                                                            • 【開催間近 - 10/17】東京 ユーザー交流会 Vol.3 参加登録 受付中!(参加無料)

                                                                                                              ユーザーの皆さま、こんにちは。コミュニティチームの藤澤です。 10/17(金)に、東京・新橋で「東京 ユーザー交流会 Vol.3」を開催します! ZOHOLICSよりも小規模なイベントですので、「リアル開催はちょっと緊張する…」という方も、安心してご参加いただけます✨ 当日は、初公開の事例を2つご紹介予定です! なお、セッション映像のアーカイブ配信は予定していないため、会場にお越しいただいた方だけが、登壇者へ直接質問したり、リアルな声を聞いたりできる貴重な機会となっています。 ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
                                                                                                            • multiple contacts for one account

                                                                                                              We currently use Zoho CRM where each Account represents a club or organization, and each Contact represents a manager or owner. However, some of our managers own or manage multiple clubs, and Zoho only allows a contact to be linked to one account at a
                                                                                                            • Rich text Merge field - Not using font specified in HTML

                                                                                                              I have a rich text merge field in a writer template which is creating a table. I have chosen to use this method instead of a repeat region because I need to specify specific cell background colours which change every time the document is created. The
                                                                                                            • Can't change form's original name in URL

                                                                                                              Hi all, I have been duplicating + editing forms for jobs regarding the same department to maintain formatting + styling. The issue I've not run into is because I've duplicated it from an existing form, the URL doesn't seem to want to update with the new
                                                                                                            • ヒートマップ詳細設定について

                                                                                                              はじめまして マーケティング担当の浅田です。 PageSenceのヒートマップ設定について質問です。 単一ページ毎の設定は上手くできるのですが 詳細設定にて、トップページのURLを含ませ全体のヒートマップを計測できないか試したところ お知らせ:データを受信していません。と表示されてしまいます。 トップページURLで始まるページの条件も試しております。 全頁を反映させたいと思い、詳細設定を上手く設定できたらと考えております。 どなたか詳しい方がいらっしゃいましたら、教えて頂けませんでしょうか 宜
                                                                                                            • Automatic category assignment

                                                                                                              Hi, I’d like to ask if there is a way to automatically assign an expense category based on the recognized Merchant. What would be the simplest way to set up automatic category assignment? Alternatively, is there an option to first choose the category
                                                                                                            • Need Help to setup plugs along with codeless bot buidler. To send sms OTPs to users via Zoho Voice and to verify it

                                                                                                              Need Help to setup plugs along with codeless bot buidler. To send sms OTPs to users via Zoho Voice and to verify it. I get leads from our website and we need to make sure those are not junk. So we are using proactive chat bot and we need mobile OTPs to
                                                                                                            • Experience with Zoho Vertical Studio

                                                                                                              I'm considering Zoho Vertical and would love to hear from some devs who've been using it. The Zoho ecosystem is pretty solid, so I assume the experience has been pretty good, but sometimes Zoho has its quirks. Overall, has your experience been positive?
                                                                                                            • LinkedIn Chrome Extension

                                                                                                              Hello - I believe it is a known issue that the LinkedIn extension Resume Extractor has stopped working and they are working on potential fixes. Wondering how others users are finding this issue and if there are any better workarounds for this issue? It
                                                                                                            • Advance PDF creation from CRM data

                                                                                                              I'm trying to create a PDF export of data in the CRM. My problem is I want a pretty complicated format for the data. I'm trying to export multiple modules worth of data, with nested one-to-many relationships between the modules. Along with that, I want
                                                                                                            • Where does this report come from in the Zoho One ecosystems?

                                                                                                              Is this directly from MA, Analytics or ??? ???
                                                                                                            • Sub-Form Padding in CSV Export

                                                                                                              Hi, When you use the Sub-Form, and for example you have a Date Field on the Main Page, then Option 1 and Option 2 fields on the Subform, when you export this to CSV the Date column will only have the Date in 1 row, the first row, it would be nice to pad
                                                                                                            • More Formula Functions

                                                                                                              Hi, I would ike for example to be able to have a Date Field and Formula Fields, and then in the Formula Fields I would like to grab just the Month of the above Date Field or the Week Number of the above Date Field. So more "Functions" than the current
                                                                                                            • File upload size limits

                                                                                                              I am designing a contact form in Zoho Creator with File upload facility. I am not sure where and how to set the following properties for the same: Allowed File Types Maximum Size of the Attachment Number of Attachments
                                                                                                            • Composite Services and Account Tracking

                                                                                                              I am looking to garner support/request the ability to make composite services. A quick search in the forums brings up multiple requests for this feature. I fail to see why an item is mandatory while services are optional. I also would like to see the
                                                                                                            • All operation codes getting Not applied in WO-TT22J1025WOR0471, SR-TT22J1025PRE0423,FOR VIN-W1K6G2AB2SL005130.

                                                                                                              Dear Support Team, Please refer attached screenshot. All operation codes getting not applied in work order. Request you to please check and update ASAP.
                                                                                                            • Customer Grouping

                                                                                                              Hi, how can I group multiple customers into single group. So that I can have idea of accounts receivables of all the customers in single group. Like if there are multiple subsidiaries of same company we have having a business with, and want to view the
                                                                                                            • Bank Receipt Catagorization

                                                                                                              Hi, how can I match a bank deposit to multiple customer's invoices ? For e.g. A single person paid to us on behalf of different five customers. I need to keep the separated invoices for each customer
                                                                                                            • "Performed changes in the query is not allowed due to following reason" when adding columns or reordering data

                                                                                                              I'm trying to make changes to a query but every time i try to save it i get this error message.  I'm not touching the data it's flagging.  All I've tried to do is reorder a couple of fields and add a new one.  Why won't it let me do this?  It's a core
                                                                                                            • Exclude Segment from Campaign Recipients

                                                                                                              I've created two Segments in order to separate Non-Marketing Contacts from Marketing Contacts. I'd like to send an Eblast to all Marketing contacts in my lists, but when I go to select Recipients, I have two options: 1. To Choose Lists to Send to; 2.
                                                                                                            • Reschedule Multiple/Mass Calls at Once

                                                                                                              When we go into a Call record, we have the option to "Reschedule Call." How can we select multiple Calls at once from the Activities tab and Reschedule them? The big use case for us: We have many leads that our reps are supposed to call on a daily basis.
                                                                                                            • Option to Empty Entire Mailbox or Folder in Zoho Mail

                                                                                                              Hello Zoho Mail Team, How are you? We would like to request an enhancement to Zoho Mail that would allow administrators and users to quickly clear out entire folders or mailboxes, including shared mailboxes. Current Limitation: At present, Zoho Mail only
                                                                                                            • I want to Make the due date of the project appears automatically

                                                                                                              hello everyone I want to know if the zoho projects app can add automatically the END DATE of the project I added the duration, start after dates of each tasks in the project template & the starting date of the project itself and the end date of it doesn't
                                                                                                            • Drag 'n' Drop Fields to a Sub-Form and "Move Field To" Option

                                                                                                              Hi, I would like to be able to move fields from the Main Page to a Sub-Form or from a Sub-Form to either the Main Page or another Sub-Form. Today if you change the design you have to delete and recreate every field, not just move them. Would be nice to
                                                                                                            • Get Zoho Mail API working (including DRE Connector, Oauth Token, ZUID, ZOID & ACCOUNT_ID)

                                                                                                              Disclaimer: I’m not a professional coder! Do you need to use Zoho Mail API? Me too. It lets you do all sorts of things — like reading the complete header of an email, or forwarding an email with its attachments — which is what I wanted to do. But setting
                                                                                                            • Kaizen #129 : Client Script Support for Blueprints

                                                                                                              Hello everyone! Welcome to another week of Kaizen. Today, let us discuss about how you can use Client Script during a Blueprint transtion to meet your requirements. This Kaizen post will provide solution for the post - Need non-mandatory fields in blueprint
                                                                                                            • Deluge Tips & Tricks: Mastering dates and times

                                                                                                              Hello everyone! We're bringing back our Deluge Tips & Tricks series, where we show you how to make the most of Deluge for achieving a wide range of use cases. Working with dates and times is a fundamental part of almost any business application. Whether
                                                                                                            • Adding a Button in a Form in Zoho Creator App

                                                                                                              Hi I want to know how can I add a Button in Zoho Creator form. I have options that I select from a multiselect options and I want the button to add those selected options in a Subform. I do not want to add on a Page Builder I want it inside a specific
                                                                                                            • Feature Enhancement Request – Text Formatting Options in Item Description (Zoho Books/Quotes Module)

                                                                                                              Dear Zoho Development Team, Greetings from Radiant360 Integrated Technical Services LLC. We would like to bring to your attention a functional limitation we've encountered within the Item Table / Quote Description section of Zoho Books (and Zoho CRM Quotes).
                                                                                                            • Internal Exception for Creator function

                                                                                                              I have been running a script successfully for several days using the scheduler in my application. Now today it suddenly creates and Internal Exception error. Nothing has changed about the script. The data is still retrievable from the web service it is using. Why would this suddenly be happening for no apparent reason? Also noticed that my usage logs are not up to date. Is something changing behind the scenes?
                                                                                                            • Next Page