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

                                                            • Function #46: Auto-Calculate Sales Margin on a Quote

                                                              Welcome back everyone! Last week's function was about displaying the discount amount in words. This week, it's going to be about automatically calculating the sales margin for a particular quote, sales order or an invoice. Business scenario Where there is sales, there's also evaluation and competition between sales reps. A healthy rivalry helps to better motivate your employees to do smart work and close deals faster and more efficiently. But how does a sales rep get evaluated? 90% of the time, it's
                                                            • 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


                                                            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

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ



                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方