Skip to main content

Zoho CRM Custom Function For Lead Phone Num Country Code Updation

Recently Zoho CRM Community had a blogpost on how to add country code to Leads along with a script to do the same. But the script seemed to leave a lot to be desired.
Here is a screenshot of their 10-line script:



These are the missing things we noticed with the above script:
1. First, there needs to be validation of whether the incoming phone number is empty or not. In the above script, even if the phone number is empty, '+91' will be added to the phone number. So, this means, in such records, phone number field will have only the value '+91'.
2. It would have been good to make it more generalized than hardcoding a specific country code into the script. Because this script is going to be applied to Leads, it is possible that the Leads may be coming in from various countries, given today's global nature of businesses. So having the script address just one country code is not going to satisfy today's growing business needs.
3. There is no checking in the script to see if the phone/mobile field already has country code in it. Suppose the phone number was already having country code, for example '+91 7788990000', then this script will give the result '+91+91 7788990000', because it doesn't do any checking if the existing phone number already has country code value prefixed with it.

Addressing the above issues, we have attempted our best to write a script which is more generalized, detailed and addresses several corner use cases. You can find it in Github here.


/*
* Zoho CRM Custom Function For Lead Phone Num Country Code Updation
* This Custom Function is for the Leads module in Zoho CRM.
* This code is in Deluge scripting language.
* This is used to check an incoming lead to see if their phone num has the country dialing code.
* If not, then this code would fetch the appropriate code based on the'Country' field value from the Lead.
* Then this would update the 'Phone' field in the CRM Lead to reflect the new number which has the country code prefixed.
*
* Note : We added a JS extension to this file so you could see some markup! :) But this is a Deluge file. Nothing Javascript about it! ;)
*
* Crafted with ♥ from India, iKosmik
*
* Got something to say? write to us at guru@zoho.academy
*/
// initialize an empty map
update_phone_no_map=map();
// Map of countires along with their international dialing code
data_set_extension_code={ "Afghanistan" : "93", "Albania" : "355", "Algeria" : "213", "American Samoa" : "1-684", "Andorra" : "376", "Angola" : "244", "Anguilla" : "1-264", "Antarctica" : "672", "Antigua and Barbuda" : "1-268", "Argentina" : "54", "Armenia" : "374", "Aruba" : "297", "Australia" : "61", "Austria" : "43", "Azerbaijan" : "994", "Bahamas" : "1-242", "Bahrain" : "973", "Bangladesh" : "880", "Barbados" : "1-246", "Belarus" : "375", "Belgium" : "32", "Belize" : "501", "Benin" : "229", "Bermuda" : "1-441", "Bhutan" : "975", "Bolivia" : "591", "Bosnia and Herzegowina" : "387", "Botswana" : "267", "Bouvet Island" : "47", "Brazil" : "55", "British Indian Ocean Territory" : "246", "Brunei Darussalam" : "673", "Bulgaria" : "359", "Taiwan" : "886", "Tajikistan" : "992", "United Republic of" : "255", "Thailand" : "66", "Togo" : "228", "Tokelau" : "690", "Tonga" : "676", "Tuvalu" : "688", "Uganda" : "256", "Ukraine" : "380", "United Arab Emirates" : "971", "United Kingdom" : "44", "United States" : "1", "United States Minor Outlying Islands" : "246", "Uruguay" : "598", "Uzbekistan" : "998", "Vanuatu" : "678", "Vatican City State" : "379", "Venezuela" : "58", "Vietnam" : "84", "Virgin Islands" : "1-284", "Virgin Islands" : "1-340", "Wallis and Futuna Islands" : "681", "Western Sahara" : "212", "Yemen" : "967", "Serbia" : "381", "Zambia" : "260", "Zimbabwe" : "263", "Aaland Islands" : "358", "Palestine" : "970", "Montenegro" : "382", "Guernsey" : "44-1481", "Isle of Man" : "44-1624", "Jersey" : "44-1534", "Curaçao" : "599", "Ivory Coast" : "225", "Kosovo" : "383", "Canada" : "1", "Cape Verde" : "238", "Cayman Islands" : "1-345", "Central African Republic" : "236", "Chad" : "235", "Chile" : "56", "China" : "86", "Christmas Island" : "61", "Palestine" : "970", "Madagascar" : "261", "Malawi" : "265", "Malaysia" : "60", "Maldives" : "960", "Mali" : "223", "Malta" : "356", "Spain" : "34", "Sri Lanka" : "94" };
phone_number_sign=("+");
//Fetching Lead information based on input Lead ID
get_lead_data = zoho.crm.getRecordById("Leads",input.lead_id);
phone=ifnull((get_lead_data).get("Phone"),"");
country=ifnull((get_lead_data).get("Country"),"");
if((phone != null) && (country != null))
{
//comparison to find the Phone extension Code on based on Lead Country
extension_code_to_add=data_set_extension_code.get(country);
if(extension_code_to_add != null)
{
// appending the Phone extension Code based on Lead Country
input_phone_number=" " + phone;
extension_to_assign=phone_number_sign + extension_code_to_add;
phone_no_to_update=extension_to_assign + input_phone_number;
//Comparision to check whether Extension Code is already Present in Phone Number
if(!startsWith(phone,phone_no_to_update) && !startsWith(phone,phone_number_sign))
{
update_phone_no_map.put("Phone",phone_no_to_update);
// Integration task to update Phone Number with Extension Code
update_data_in_crm = zoho.crm.updateRecord("Leads","" + input.lead_id,update_phone_no_map);
}
}
}

This Custom Function is for the Leads module in Zoho CRM. This code is in Deluge scripting language, which the language used across Zoho suite of products.  This is used to check an incoming lead to see if their phone num has the country dialing code. If not, then this code would fetch the appropriate code based on the'Country' field value from the Lead. 

Comments

Post a Comment

Popular posts from this blog

Achieve Zen with Zoho One

Zoho One.  Arguably the launch of the biggest software suite of Apps in the software industry yet.  When I first heard of this, I was not paying attention because I thought to myself "Just a rumor". But when I saw the launch today, it was mind-blowing! How could someone give away a suite of almost forty enterprise-ready apps for such a drop dead price?! But it's true and it is happening.  Drop-dead Pricing 38 cloud-based Apps + 55 mobile Apps. Must be a whopping price for so many Apps, right? That’s what I thought until I heard the price of $30 / month / user! That works out to about just $1.36/day/user, or rather, a little more than 15 cents/working hour/user! Cheaper than a cup of coffee! One for All. All for One. It’s is a very powerful concept. Come to think of it. All for one. All the business apps that you needed so far and possibly will ever need. One for all. One Suite. One login. One place for all your data so you can start connecting them together and making b...

What is a CRM software - Part 3 - Lead Followup Workflow

Getting in Leads into the system is only half the story. Now, for the better half - following up with leads. The key to following up with Leads is to maximize conversion, as we know. It’s an ongoing challenge. Market situation may change. Competition landscape will undergo its own changes. So it’s not just enough to have a lead workflow, but it is crucial to measure its ongoing success rate as you keep using the workflow. Let’s talk about this in more detail. 
 Things to Remember Bucket-Based Followup So now we have categorized Leads into buckets, based on strategies we discussed in the previous post. It might be useful to come up with a different workflow for different buckets. Someone might have a 90% chance to convert to a customer, whereas someone else may have only a 20% chance. You may want to treat these leads differently when following them up, so that you allocate your salesperson to do more followups with those leads who have higher probability of conversion.  
 Modes of ...