Function-36: Figure out how long and how much it takes to convert a lead to a deal!

Function-36: Figure out how long and how much it takes to convert a lead to a deal!



Welcome back everyone!

Last week, we learnt how to close all tasks associated with a lead and create a new task. This week, let's look at a function that lets you 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.

Business scenario: 

We all know how much work goes into handling a lead, negotiating and converting them into deals. It doesn't stop there though. From the start of interacting with a lead to completing the deal and producing an invoice, the work included is too much. But that tedious and endless work becomes quantifiable contribution towards your organization.

Also having all the completed interactions documented and sorted out, you get an idea of how the mindset of customers work, or what are the current trends, etc. Don't look down on this little stat. A person who loves to talk in calls would be easier to convert a lead if the activity created is a call. Sending emails to such a customer might backfire.

So, how about having a custom button with a function that makes it possible to compile the total activities related to a lead. In addition, sort the activities based on the specific dates to get a clearer picture. For instance, displaying the number of days between the First activity created time (for the lead record) and the Lead converted date, updated in a custom number field.

Getting started with the custom function:

  • Go to Setup > Customization > Modules > Deals > Links and buttons > Create new button.
  • Provide a name for the button. For example: "Activities with Dates - Leads". Add a description(optional).
  • Select the placement of the button as View page.
  • Select the action to be performed as "Writing function".
  • Copy the code given below.
  • Click “Edit arguments”.
  • Enter the name as “recid” and select the value as “Lead Id”.
  • Enter the name as “leadowner” and select the value as “Lead owner id”.
  • Click Save&Execute Script.
  • Save the script.
  • Select the profiles who can view this button.
  • Click Save.

The script:


Code for Version 2.0 API:


Sum of Total Activities(Open and Closed):

RelatedTasks = zoho.crm.getRelatedRecords("Tasks", "Leads", leadId.toLong(),1);

RelatedEvents = zoho.crm.getRelatedRecords("Events", "Leads", leadId.toLong(),1);

RelatedCalls = zoho.crm.getRelatedRecords("Calls", "Leads", leadId.toLong(),1);

totalcount = RelatedTasks.size() + RelatedEvents.size() + RelatedCalls.size();

mp = map();

mp.put("Activities_Count", totalcount);

update = zoho.crm.update("Leads", leadId.toLong(), mp);

info mp;

info update;

return "Success";


Sum of Total Activities(Open and Closed) for a particular time period(First Activity Created to Lead Converted Time):

converteddate = input.convertdate.toDate();

RelatedTasks = zoho.crm.getRelatedRecords("Tasks", "Leads", leadId.toLong(),1);

datelist = List();

for each task in RelatedTasks

{

taskcreateddate = task.get("Created_Time").toDate();

datelist.add(taskcreateddate);

}

RelatedEvents = zoho.crm.getRelatedRecords("Events", "Leads", leadId.toLong(),1);

for each event in RelatedEvents

{

eventcreateddate = event.get("Created_Time").toDate();

datelist.add(eventcreateddate);

}

RelatedCalls = zoho.crm._getRelatedRecords("Calls", "Leads", leadId.toLong(),1);

for each call in RelatedCalls

{

callcreateddate = call.get("Created_Time").toDate();

datelist.add(callcreateddate);

}

datevalue = datelist.sort().get(0);

daysdiff = days360(datevalue.toDate(),converteddate);

mp=map();

mp.put("Field_Name",daysdiff);

update = zoho.crm.update("Leads", leadId.toLong(), mp);

info mp;

info update;

return "Success";


Code for Version 1.0 API:


For V1 API - Old Editor - Sum of Total Activities(Open and Closed):

leadIdStr = input.leadId.toString();
RelatedTasks = zoho.crm._getRelatedRecords("Tasks", "Leads", leadIdStr,1,200);
RelatedEvents = zoho.crm._getRelatedRecords("Events", "Leads", leadIdStr,1,200);
RelatedCalls = zoho.crm._getRelatedRecords("Calls", "Leads", leadIdStr,1,200);
totalcount = RelatedTasks.size() + RelatedEvents.size() + RelatedCalls.size();
mp = map();
mp.put("Activities Count", totalcount);
update = zoho.crm._updateRecord("Leads", leadIdStr, mp);
info mp;
info update;
return "Success";

For V1 API - Old Editor - Sum of Total Activities(Open and Closed) for a particular time period(First Activity Created to Lead Converted Time):

leadIdStr = input.leadId.toString();
converteddate = input.convertdate.toDate();
RelatedTasks = zoho.crm._getRelatedRecords("Tasks", "Leads", leadIdStr,1,200);
datelist = List();
for each task in RelatedTasks
{
taskcreateddate = task.get("Created Time").toDate();
datelist.add(taskcreateddate);
}
RelatedEvents = zoho.crm._getRelatedRecords("Events", "Leads", leadIdStr,1,200);
for each event in RelatedEvents
{
eventcreateddate = event.get("Created Time").toDate();
datelist.add(eventcreateddate);
}
RelatedCalls = zoho.crm._getRelatedRecords("Calls", "Leads", leadIdStr,1,200);
for each call in RelatedCalls
{
callcreateddate = call.get("Created Time").toDate();
datelist.add(callcreateddate);
}
datevalue = datelist.sort().get(0);
daysdiff = days360(datevalue.toDate(),converteddate);
mp=map();
mp.put("Field Name",daysdiff);
update = zoho.crm._updateRecord("Leads", leadIdStr, mp);
info mp;
info update;
return "Success";

 

Note:

  • You can also set this button in the List View page of the Module, to see the stats of all records simultaneously.
  • The code is zoho.crm._getRelatedRecords for Version 1.0 of APIs.

 

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.

 

See you all next week with another interesting custom function. Ciao! 


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.





                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation
                                        • Sticky Posts

                                        • Tip #35 - On using Kanban View in Zoho CRM

                                          Hi folks,  It's that time of the week again, and I am back with a quick tip about using Kanban View in Zoho CRM. If you think you missed any of our previous weeks' tips, you can read them here.  Tip #35 - On using Kanban View in Zoho CRM You deal with so many records in CRM every single day! When you click open each module in Zoho CRM, you have hundreds of records, each in various stages of your sales pipeline. Wouldn't it be cool if you had them all sorted automatically without having to filter
                                        • ZUG (Zoho User Group) In-person Meetups - Learn, share and discuss all things Zoho

                                          Hi, Hope you all are well. We're excited to announce our second leg of in-person Zoho User Group (ZUG) meetups in your region. A quick update - Our first leg of meetups in 2024 progressed and reached completion smoothly, where Zoho experts had the opportunity
                                        • ZUG (Zoho User Group) In-person Meetups - Learn, share and discuss all things Zoho

                                          A big warm hello to the Zoho Community, and Happy new year to all of you! We're thrilled to let you know that our ZUG Meetups for 2024 have almost begun, and we can't wait for you to be a part of them. We have some interesting topics in store for this
                                        • Cloning Email Templates across modules in Zoho CRM.

                                          The option of cloning email templates across modules has been a long standing feature request from the Community. Thank you all for being so patient with us. We are happy to inform you all that this enhancement has been rolled out. Just in case you haven't noticed it already, cloning email templates is possible now! Cloning is useful because it cuts down the hassle of having to create the same email templates again for different modules. Here are the steps: Navigate to Settings---> Customization--->Templates
                                        • CRM Hack #2: Automate sending of birthday greetings to your customers.

                                            Hello everyone! What sets you apart as a sales person is your ability to add that personal touch to your business relationship with your customers. Sending a gift on a special day, or leaving a note wishing them on their birthdays, are small, yet significant actions that show your customers that you care. And these are actions done without any expectations :) You must be engaging with a lot of customers and it is highly unlikely that they all are your friends on Facebook or some social channel,


                                        Manage your brands on social media



                                                Zoho TeamInbox Resources

                                                  Zoho DataPrep Resources



                                                    Zoho CRM Plus Resources

                                                      Zoho Books Resources


                                                        Zoho Subscriptions Resources

                                                          Zoho Projects Resources


                                                            Zoho Sprints Resources


                                                              Qntrl Resources


                                                                Zoho Creator Resources


                                                                  Zoho WorkDrive Resources



                                                                    Zoho Campaigns Resources

                                                                      Zoho CRM Resources

                                                                      • CRM Community Learning Series

                                                                        CRM Community Learning Series


                                                                      • Tips

                                                                        Tips

                                                                      • 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