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.

    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

                                                            • How to reach the official Zoho Support channels and avoid fake ones.

                                                              Dear Customers, Thanks a lot for choosing Zoho! Our applications are built to help achieve your day-to-day business goals. We are committed to engaging with you, to understand and develop solutions that enhance your productivity.  We are happy and ready to help you use our services effectively. Understanding and avoiding fake support Just like using popular bank names and financial applications for phishing purposes, using Zoho and claiming to be providing Zoho Support or services with false numbers
                                                            • Function #35: Close all tasks associated with a lead and create a new task.

                                                              Welcome back everyone! Last week, we learnt how to close all tasks of a deal depending upon the deal stage. This week, let's look at a custom function that lets you close all of the tasks associated with a lead while simultaneously creating a new task, like when you need to halt all progress towards a lead while the lead is not available at the moment but create a reminder task. Business scenario: The success of a company, in one way or another, is determined by the leads it gets. Each lead is just
                                                            • Zoho CRM Webinar - Redesigning Daily User Experiences with Canvas

                                                              <br> Your users across roles use the CRM for day-to-day tasks that are necessary. Whether they perform their tasks on time, the right way, or at all depends on a lot of factors, including User Experience. Many businesses struggle with rigid layouts,
                                                            • Join us at the Canada ZUG Meetup: What’s New in Zoho CRM

                                                              Hello Zoho Community! Start your year with fresh insights into Zoho CRM’s latest updates and tools. Whether you're a CRM beginner or a experienced user, this meetup is crafted to help you optimise your processes and leverage new features. Explore practical
                                                            • 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 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


                                                                                                      ご検討中の方




                                                                                                              • Recent Topics

                                                                                                              • Printing mailing labels

                                                                                                                The ability to print mailing labels would seem to be an important, basic, function of a good CRM. I find it very surprising that this has still not been addressed adequately by Zoho. When trying to use the existing "mailing label" included: 1. the data
                                                                                                              • Pageless mode needed to modernise Writer

                                                                                                                When we switched from GSuite to Zoho, one of the easiest apps I found to give up, was Docs. In many ways, Writer has always been more powerful than Docs, especially in terms of workflows/fillable forms/etc. However, I went back into Docs because I notice
                                                                                                              • Zoho Projects - Visual improvement to parent and sub-task relationship

                                                                                                                Hi Projects Team, My feature request is to improve sub-task visibility. Please see screenshot below. I really think parent child relationships could be visually improved. Even if the first letter of the parent task was inline with other same level tasks
                                                                                                              • AI Interview Insights: Turn Recorded Interviews into Quick Transcripts & Summaries

                                                                                                                Evaluating interviews shouldn’t require replaying long recordings or taking manual notes. With AI Interview Insights, you can now review complete transcripts and AI-generated summaries of your One-way (Recorded) interviews right inside Zoho Recruit. This
                                                                                                              • API method to get activity feed in Recruit

                                                                                                                Hi community, I'm trying to figure out - is there any API method tto get information about datetime when Recruit/Candidates record tag where added?
                                                                                                              • Printing Mailing labels

                                                                                                                Is there any way to adjust the size of the printing labels? or product would I use to print labels from Zoho? Thanks, Josef Krieger Moderation Update (14th April 2025): We have another post discussing the same topic with votes and feedback from users.
                                                                                                              • Default to Current Date

                                                                                                                I'm importing data from a excel spread sheet that does not have date column and I'd like the date column in the Zoho Database to default to the current date. Any way I can do this?
                                                                                                              • "Spreadsheet Mode" for Fast Bulk Edits

                                                                                                                One of the challenges with using Zoho Inventory is when bulk edits need to be done via the UI, and each value that needs to be changed is different. A very common use case here is price changes. Often, a price increase will need to be implemented, and
                                                                                                              • Different Company Name for billing & shipping address

                                                                                                                We are using Zoho Books & Inventory for our Logistics and started to realize soon, that Zoho is not offering a dedicated field for a shipping address company name .. when we are creating carrier shipping labels, the Billing Address company name gets always
                                                                                                              • What's New in Zoho Inventory | Q2 2025

                                                                                                                Hello Customers, The second quarter have been exciting months for Zoho Inventory! We’ve introduced impactful new features and enhancements to help you manage inventory operations with even greater precision and control. While we have many more exciting
                                                                                                              • Make Packages from multiple sales order of a single customer

                                                                                                                Our customers sends orders to us very frequently, some times what customer wants is to ship items from 5 to 6 sales orders in a single shipment. it will be very nice if, zoho can implement this function, in which we can select items from other sales orders of the customer.
                                                                                                              • Print a price list or price book

                                                                                                                Hi Community. Am I right in concluding that Zoho has no functionality to print a price list from either Zoho CRM, Zoho Inventory or Zoho Books? I won't get stuck on the fact that Zoho doesn't sync price books between Zoho CRM and Books/Inventory (more
                                                                                                              • Show Custom Button in Portal Listview Canvas

                                                                                                                I have created a custom button that shows in a list view of deals (internally I can see it). I have permissions to allow this button on the portal. But it is not displaying in the canvas list? Before I do too much leg work, is this function allowed?
                                                                                                              • Zoho Sites "pages" management page

                                                                                                                I have 80 plus pages on zoho sites. When I go to the "pages" link to view and edit pages, They are not in any kind of order, so I spend lots of time searching for pages when I need to edit or create new. How can I change the view order of all my pages
                                                                                                              • AI feature in Zoho Desk suggesting answers based on past ticket threads

                                                                                                                Hi I would like to suggest something that would be very useful : instead of suggesting answers based on the Knowledge Base, I think it would be great if Zia could analyze the history of all customer and agents threads, to suggest answers in new tickets.
                                                                                                              • Advanced Customization of the Help Center using JavaScript

                                                                                                                Hello everyone, The Help Center in Zoho Desk can be customized by using HTML and CSS to provide structure and enhance the page's appearance—but what if you want to add interactive and dynamic elements? You can add these effects with JavaScript, a programming
                                                                                                              • Introducing Zoho POS for the Kingdom of Saudi Arabia

                                                                                                                Hey everyone, We are excited to kick-start December with a completely personalized edition of POS for retail businesses in Saudi Arabia to help run your operations with ease. It offers four different subscription plans—Free, Standard, Professional, and
                                                                                                              • Unveiling Zoho Sites 2.0 - A new dimension in website building

                                                                                                                Dear Zoho Sites Users, We are thrilled to announce the launch of Zoho Sites 2.0 today! This refresh represents a significant step forward in the capabilities of Zoho Sites and is crucial for creating a lasting and positive impact on our customers' businesses.
                                                                                                              • Script Editor not an option

                                                                                                                I am trying to apply a script to a sheet and Script Editor is not an option. I don't want to go outside Sheets to do this (like Creator) if it can be done inside Sheets.
                                                                                                              • Not able to link email text.

                                                                                                                Kindly check Zoho Sites. I am unable to turn a text into a email link. The save button does not work. Kindly try yourself to see it not responding to save.
                                                                                                              • Migrate data from old to new account

                                                                                                                Hy, Have one Old Zoho Notebook Account with Data , want to migrate that whole Data to New Zoho Notebook Account which is in Zoho One . Is that possible ? If Yes then how?
                                                                                                              • Zoho Analytics Regex Support

                                                                                                                When can we expect full regex support in Zoho Analytics SQL such as REGEXP_REPLACE? Sometimes I need to clean the data and using regex functions is the easiest way to achieve this.
                                                                                                              • Add Custom Reports To Dashboard or Home Tab

                                                                                                                Hi there, I think it would be great to be able to add our custom reports to the Home Tab or Dashboards. Thanks! Chad
                                                                                                              • Pricing Strategies: #1 Nuances in Pricing

                                                                                                                When Clara first opened her digital printing shop, pricing was simple. She sold handmade greeting cards, planners, business cards, and other physical items at fixed label prices, individually and in bulk. One SKU, one price, one bill, and that's all it
                                                                                                              • [Free Webinar] Learning Table Series – Education Management in Zoho Creator

                                                                                                                Hello Everyone! We’re excited to invite you to another edition of Learning Table Series, where we showcase how Zoho Creator empowers industries with innovative and automated solutions. About the Learning Table Series The Learning Table Series is a free,
                                                                                                              • CRM x WorkDrive: File storage for new CRM signups is now powered by WorkDrive

                                                                                                                Availability Editions: All DCs: All Release plan: Released for new signups in all DCs. It will be enabled for existing users in a phased manner in the upcoming months. Help documentation: Documents in Zoho CRM Manage folders in Documents tab Manage files
                                                                                                              • Move attachments from one module to another with Deluge

                                                                                                                I have created a button that works just like the convert button for my custom modules. I would like this custom function to move any attachments in this record to the new module. I can't seem to find any documentation on how this can be accomplished.
                                                                                                              • Help in function code

                                                                                                                Hi, could someone look at the code below and tell me what 's wrong with it? After a deal creation or edition the code should find the related Account, than all open Deals for that Account and copy the field Total_Open_Deals from the Account record to
                                                                                                              • Automation Series: Auto-update Phase Status

                                                                                                                Hello Folks! You can auto-update your phase's status based on status of underlying tasks using custom functions. In this series, we will showcase how to create and run custom functions, using Deluge, with ease. Follow the steps below and automate your
                                                                                                              • how to add subform over sigma in the CRM

                                                                                                                my new module don't have any subform available any way to add this from sigma or from the crm
                                                                                                              • Zoho Projects - Project Details on the Project Menu

                                                                                                                Hi Project's team, I've helped may businesses setup and use Zoho Project and one thing I see time and time again is confusion on where to find the Project Details information. I would be much more intuitive if Project Details was on the menu before Dashboard.
                                                                                                              • Zoho Projects - Add Feed to Project Tabs

                                                                                                                Hi Projects Team, I'm working on a lightweight communications requirement for one of my customers in relation to communicating with their client users via Zoho Projects. I noticed that the Feed is only available in the Collaboration section, but you can
                                                                                                              • Flow - Fetch info from drop down in another module

                                                                                                                I am running into a road block which I thought would be a simple task. My goal - The account is assigned to a "route" which can be selected from a drop down menu and adds a tag to the account accordingly (easy enough). Now when I create a task for this
                                                                                                              • Show unsubscribed contacts ?

                                                                                                                Hello, I would like to display the unsubscribed contacts. Unfortunately, I do not have this subscription type as described in the documentation (https://help.zoho.com/portal/en/kb/marketing-automation-2-0/user-guide/contacts/contact-management/articles/subscription-type-24-1-2024#Subscription_Type_field.)
                                                                                                              • Zoho Developer Community Hackathon 2025 is LIVE!

                                                                                                                Hey developers! It’s that time of the year again — the Zoho Developer Community Hackathon 2025 is officially open for registrations! If you’ve been waiting for a chance to stretch your skills, try something new, or finally bring that idea to life, this
                                                                                                              • Converted Leads Not Showing in Lead Reports

                                                                                                                Converted leads are not showing in the Lead reports. How can I make converted leads visible in the report,
                                                                                                              • Text widgets in dashboards

                                                                                                                Having a text widget in a dashboard would help immensely. It would allow adding links to related documents, relevant CRM views, etc. It would allow adding explanations of the data displayed in the other widgets, about how to interpret them or about filtering.
                                                                                                              • [Webinar] Zoho Writer for content creators and publishing houses

                                                                                                                Managing multiple drafts, edits, and client reviews doesn't have to slow you down. Join our upcoming webinar to see how Zoho Writer helps content creators and publishing houses create, edit, and publish seamlessly—all in one place. You'll learn how to:
                                                                                                              • Adding Reports to Portals

                                                                                                                Is there a way to add Reports to portals so only the user can see report templates relevant to them?
                                                                                                              • How to assign one Manual to multiple Spaces?

                                                                                                                Hello, I have two spaces, one called tech knowledge and the other one called HR knowledge. I have a manual that is called HR tech. I want to assign this manual to HR knowledge and tech knowledge. How should I do that?
                                                                                                              • Next Page