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




                                    Zoho Desk Resources

                                    • Desk Community Learning Series


                                    • Digest


                                    • Functions


                                    • Meetups


                                    • Kbase


                                    • Resources


                                    • Glossary


                                    • Desk Marketplace


                                    • MVP Corner


                                    • Word of the Day



                                        Zoho Marketing Automation


                                                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 Campaigns 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

                                                                                                  • How to select multiple notes at once in the PC client?

                                                                                                    In the PC client, you can select notes using ctr+LMB. But why can't you use shift+LMB? PC version 3.2.0
                                                                                                  • Feature Request: Search in the PC client. Some thoughts about the search.

                                                                                                    Hi all. I'm really excited to start using Zoho Notebook, but I'm missing some of the search capabilities on my desktop. There are also some thoughts on improving search in general. Search is very important to me, without it it is difficult for me to use
                                                                                                  • Directly Edit, Filter, and Sort Subforms on the Details Page

                                                                                                    Hello everyone, As you know, subforms allow you to associate multiple line items with a single record, greatly enhancing your data organization. For example, a sales order subform neatly lists all products, their quantities, amounts, and other relevant
                                                                                                  • Increase Round Robin Scheduler Frequency in Zoho Desk

                                                                                                    Dear Zoho Desk Team, We hope this message finds you well. We would like to request an enhancement to the Round Robin Scheduler in Zoho Desk to better address ticket assignment efficiency. Current Behavior At present, the Round Robin Scheduler operates
                                                                                                  • Separate One-Time Mentions from Ongoing Ticket Following in Zoho Desk

                                                                                                    Dear Zoho Desk Support Team, We are writing to request an enhancement to the mention functionality within Zoho Desk. Currently, when an agent is mentioned in a ticket, they receive notifications for all subsequent activity on that ticket, similar to being
                                                                                                  • Create Your Own Issue Management System

                                                                                                    Effective issue management is a cornerstone of project success. Every bug or issue, no matter how small, needs to be tracked and resolved in time to maintain project momentum. In this post, we’ll explore how an issue management system in Zoho Projects
                                                                                                  • Client Script - mapping data from different module

                                                                                                    Dear ZOHO Team Firstly I need to describe the need - I need to have data from Contacts module based on lookup field - the 5 map limit is not enough for me because I have almost 20 fields to copy So I have decided to make a Customer Script - and from unknown
                                                                                                  • Emails linked to Deal

                                                                                                    Hello everyone, I’d like to ask a question to see if someone can help me out. We are requesting availability from suppliers by sending emails directly from the Opportunity. These emails we send are logged within the Opportunity; however, when we receive
                                                                                                  • Zoho Analytics Pivot Table - How to compare month vs last year same month

                                                                                                    Hi, I had created a pivot table with setup as below: Column: - Delivery Date Row: - Customer Group Data as column - Total amount (sum > normal) (show data of the month) - Total amount (sum > % difference from previous value) (compare between this month
                                                                                                  • Employees can not add some expenses suddenly

                                                                                                    Zoho expense was working fine and whenever there was a new merchant, it would automatically add and also the same auto added in Zoho Books (due to merchant-vendor sync) untill now. From today, it is having problems in searching the existing vendors and
                                                                                                  • Zoho Creator Upcoming Updates - December 2024

                                                                                                    Hi all, We're excited to be back with the latest updates and developments on the Creator platform. Here's what we're going over this month: Deluge AI assistance Rapid error messages in Deluge editor QR code & barcode generator Expandable RTF and multi
                                                                                                  • Workflow - Execute Based on Date

                                                                                                    Hello, I have trouble understanding the documentation for Execute Based on Date or Date Time Field's Value. I want to send an email every time I have a Case opened for more than three days with its status unchanged. I set : This rule will be executed 3 days after [date].  Condition : Status is [New]. Instant Action : Send an email notification. However, I'm not sure I follow this part of the documentation: "For all the records matching the rule criteria, rule will be triggered either monthly or yearly
                                                                                                  • Lookup Fields not Converting

                                                                                                    I manage holiday properties. I have a lookup to the Accounts (Properties) in the Leads module. The lookup is connected to the property address field. When I convert it the lookup field does not update in Deals, although the property address does. There
                                                                                                  • Important updates to Zoho CRM's email deliverability

                                                                                                    Last modified on: Jul 24, 2024 These enhancements are released for all users across all data centers. Modified on: Oct 30, 2023 Organisations that are in the Enterprise and above editions of Zoho CRM, and have not authenticated their email-sending domains
                                                                                                  • Expanded data-capturing capabilities with enhanced tabular sections

                                                                                                    We are thrilled to announce an update to Zoho Recruit that brings even more flexibility and customization to your recruiting process. With the addition of 10 new field types to the tabular sections, you now have the power to enhance your tabular sections
                                                                                                  • Files Uploaded to Zoho WorkDrive Not Being Indexed by Search Engines

                                                                                                    Hello, I have noticed that the files I upload to Zoho WorkDrive are not being indexed by search engines, including Google. I’d like to understand why this might be happening and what steps I can take to resolve it. Here are the details of my issue: File
                                                                                                  • Marketing Automation Emails Going to Spam

                                                                                                    Google is trapping all the marketing automation emails in spam. My domain has a perfect reputation and it looks like Zoho has a low reputation which is sending it to spam. When I pull the email out of spam and click on a link in the email, I get this
                                                                                                  • I'm getting an "Invalid_scope" error, even though I used an access token generated with the correct scope.

                                                                                                    I'm getting an "Invalid_scope" error, even though I used an access token generated with the correct scope. Here’s what I did in Postman: Generated the code to create an access token using the following URL: https://accounts.zoho.eu/oauth/v2/auth?scope=ZohoCampaigns.contact.UPDATE&client_id=<client_id>&response_type=code&access_type=offline&redirect_uri=https://1882-2-26-193-161.ngrok-free.app
                                                                                                  • Customer can't comment on SO or Invoice

                                                                                                    Hi I just saw that my customers are not able to submit a comment either on invoices or sales order. What happens if my customer hits submit is just nothing. only a red line appears on top of the page which probalby indicates an error. I'm not able to
                                                                                                  • Convert Request to Forum Topic

                                                                                                    I know you can convert a forum topic to a request and a request to a solution in the knowledge base, but how do you convert a request to a forum topic?  Is this possible?  If not is this a feature coming down the pipe in the near future? Thanks!
                                                                                                  • Integration of Business Hours in Email Templates

                                                                                                    Dear Zoho Desk Team, We would like to propose a feature enhancement to Zoho Desk that would greatly improve the utility of the Business Hours settings and streamline communication with our clients. Feature Request: Integration of Business Hours in Email
                                                                                                  • Send To Zoho Sign not Showing

                                                                                                    The button send to Zoho sign is not showing on my Zoho CRM . Is there additional steps I need to take after installing Zoho Sign to CRM ?
                                                                                                  • Easy way to delete attachments

                                                                                                    I've reached my data limit and would like to run a view/report, and mass delete attachments. Is there an easy, fast way to do this? Moderation Update: Post Summary: There are two features the post discusses a) Easy way to remove Email attachments Will
                                                                                                  • Vivaldi will not open the Zoho Mail app when I click a email link in the browser

                                                                                                    I'm running Vivaldi on Arch with the Plasma desktop and have under default applications Zoho Mail set as my default email client. Whenever I click a email link in Vivaldi I get the below when it should be launching Zoho. Any ideas on rectifying this issue?
                                                                                                  • Zoho Sign / Prefill By You - Editable by Them!

                                                                                                    Zoho Sign seems to have two field options available - an empty field for signer(s) to complete or a field that has been prefilled by you, that becomes read only once sent.  What I would like is an option on the pre-filled by you fields, to leave them
                                                                                                  • How to transfer all my mails from Zoho to Gmail or Office 365

                                                                                                    is there any option to move my emails from zoho to gmail or office 365. i would like to export more than 25k emails from zoho to office 365 or gmail. can anyone help me to guide properly. this will help me to access my emails easily i have both account and can easily  do it with office 365 or gmail. i want two options. direct from zoho to office 365  or exported eml files from zoho to gmail. please suggest me both if possible 
                                                                                                  • Is the Contacts sync between Campaigns and CRM bi-directional?

                                                                                                    Is the Contacts sync between Campaigns and CRM bi-directional?
                                                                                                  • Task does not syncing to google calendar shedual

                                                                                                    Hi why does the tasks activities do not syncing with the google calendar like the event option does?
                                                                                                  • ZOHO Widget SDK not loading in html

                                                                                                    I have this code below, I have imported the widgetsdk however I get the error shown in the image, I have tried many different ways of importing and initiating the function ZOHO but nothing is working. can someone explain what I'm doing wrong, if I am
                                                                                                  • Bug with Zobot Human transfer

                                                                                                    I have configured the brand, the operator, and the Zobot in Spanish. However, no matter what I do, it always says "YES" instead of "Sí" or "Sure, why not " instead of "Claro, ¿por qué no?" when asking if the user wants to contact a human operator. The
                                                                                                  • Advice for my first project in Zoho

                                                                                                    Hello, how can I design and implement a customized ERP and CRM system using Zoho to automate and manage core business functions, including customer relationship management, property inventory, sales tracking, and financial processes. This is one of my
                                                                                                  • Error AS101 when adding new email alias

                                                                                                    Hi, I am trying to add apple@(mydomain).com The error AS101 is shown while I try to add the alias.
                                                                                                  • This mobile number has been marked spam. Please contact support.

                                                                                                    Hi Support, Can you tell me why number was marked as spam. I have having difficult to add my number as you keep requesting i must use it. My number is +63....163 Or is Zoho company excluding Philippines from their services?
                                                                                                  • email address autocomplete

                                                                                                    Is there a way to eliminate certain addresses from showing up in auto complete when entering an address? Many old and unused addresses currently show up, many of which I would like to get rid of. Thanks
                                                                                                  • Something went wrong. One or more fields contain errors

                                                                                                    I am getting this error but there is no way to debug what field is causing the issue . I have over 100 fields. Everything was working fine and then i fixed some fields that should have the same field names but had a typo and i am getting this error. It
                                                                                                  • Integrating Zoho Desk Instances from two separate organizations

                                                                                                    Is it possible to integrate Zoho Desk with an instance from another organization? For example, creating a ticket in one organization can cause the creation of a ticket in the second organization? Or certain tickets from one organization be viewable by
                                                                                                  • Send Whatsapp with API including custom placeholders

                                                                                                    Is is possible to initiate a session on whatsapp IM channel with a template that includes params (placeholders) that are passed on the API call? This is very usefull to send a Utility message for a transactional notification including an order number
                                                                                                  • Knowledge base bug - Error: Article couldn't be updated.

                                                                                                    It took me a while to figure this out, truly one of the most irritating bugs in Zoho. I hope you find this information helpful. When using the knowledge base to create articles, make sure your keywords are in lowercase and separated by commas. Otherwise,
                                                                                                  • Is this possible with Campaigns?

                                                                                                    My company is currently moving CRM's from Monday to Zoho One. Currently, our marketing lead process is send out 7 sms messages over 14 days if the lead is in a certain status. If we don't get a response the lead is put into a "Closed" status. Do we buy
                                                                                                  • How to view two portals (Zoho CRM & Zoho Books) in single login

                                                                                                    Hello there, I need to create a portal access for the Customers. Customer data present in two applications namely Zoho CRM & Zoho Books. My requirement is to show the two different portals(Zoho CRM Portal & Zoho books Portal) in single login. I could
                                                                                                  • Next Page