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:
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):
Note:
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!
Writer is a powerful online word processor, designed for collaborative work.