Welcome back everyone!
Last week, we learnt how to add country codes to phone numbers. This week, let's look at a custom function that allows you to assign leads by matching the lead acquisition time and your sales reps' shift timing.
Did you know?
Research shows that
- Vendors who respond first to a prospect win 35-50% of the deals.
- The chances of converting is 9x more if you reach a prospect within the first 5 minutes.
Business scenario:
The stats above prove an important point - the quicker your lead assignment, the better the chances of winning the deal. While auto-assigning on round-robin basis helps balance the load, it does not help meet the need of having to quickly reach out to your prospects operating across geographies. Assigning leads based on the time at which they are created, solves this problem. This is done by matching the lead acquisition time with sales reps' shift timing. This week's custom function helps do just that.
Getting started with the custom function:
- Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own.
- Provide a name for the custom function. For example: “Add Country code-1”. Add a description(optional).
- Select the module as Leads. Add a description(optional).
- Click “Free flow scripting”.
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “leadId” and select the value as “Lead Id”.
- Save the changes.
The script:
Code for Version 2.0 API:
leadDetails = zoho.crm.getRecordById("Leads", input.leadId.toLong());
//info leadDetails;
createdhour = ifnull(leadDetails.get("Created_Time"),"").toTime("yyyy-MM-dd'T'HH:mm:ss").getHour();
info createdhour;
if ((createdhour >= yy ) && (createdhour < zz ))
{
mp=map();
mp.put("Owner",xxxxxxxxxx);
update=zoho.crm.update("Leads", leadId.toLong(), mp);
info mp;
info update;
}
Code for Version 1.0 API:
leadIdStr = input.leadId.toString();
leadDetails = zoho.crm.getRecordById("Leads", input.leadId);
info leadDetails;
createdtime = ifnull(leadDetails.get("Created Time"),"");
createdhour=createdtime.toString("dd-MM-yyyy HH:mm:ss").toTime().getHour();
info createdhour;
if ((createdhour >= yy ) && (createdhour < zz ))
{
mp=map();
mp.put("SMOWNERID","xxxxxxxxxxxxxx");
update=zoho.crm.updateRecord("Leads", leadIdStr, mp);
info mp;
info update;
}
Note:
- Change the 'xxxxxxxxxxxxxx', to the User ID of the specific user.
- The 'yy' and 'zz' refer to the time at which a lead is created. Use 24 hour time to set up a custom time window..
- Assigning to a user requires the User ID and not the user name. The user ID is found in the Setup page of your CRM. Take a look at the screenshot below for more details.
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.