Leads can come from different sources, such as website forms, social media, campaigns, cold calls, and events. Sometimes, these leads get created without a country code added to their phone number or, worse, without a phone number. Your salespeople then need to edit the lead record manually, update the country code, and call them from within the CRM. What if there were a quick workaround that updates the leads' respective country codes without any manual intervention? A custom function helps you do so whenever a lead gets created in your CRM account.
Since this is a special requirement for most businesses, we support it through low-code tools that you can connect with workflow rules. This custom function helps you enter the corresponding country code to phone numbers, making calls directly from CRM convenient.
Permissions and availability
- Users with the Manage Automation permission can create and update workflow rules.
- Users with the Manage Extensibility permission can create custom functions.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Create a workflow rule for the Leads module to update the country code upon creating a lead. Learn more
- Write a custom Deluge function and link it up with the workflow rule. Learn more
- Test the function in a sandbox before deploying it in your production environment. Learn more
Create a workflow rule
Follow the steps below to create a workflow rule in your Zoho CRM account:
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select the Module as Leads from the drop-down list.
- Provide a name for the rule. For example: "Update country code in lead records".
- Add a description(optional) and then click Next.
- In the Execute this workflow rule based on section, choose Record Action, then select Create from the drop-down.
- In the Which leads would you like to apply the rule to? section, specify the condition as "<Phone> <is not empty>", then click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a Name and description, if necessary, for the function.
- On the Deluge Script Editor, do the following:
- Copy and paste the code given below.
- Click Edit Arguments.
- Choose Lead Id and name it as leadId.
- Click the + icon to add more arguments.
- Choose Country and name it as country, then click Save.
- Click Save & Execute Script.
- Click Save on the workflow rule page.
The code
//initialize an empty map
update_phone_no_map=map();
//Map countries along with their international phone 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=("+");
//Fetch lead information based on input Lead ID
get_lead_data = zoho.crm.getRecordById("Leads",input.leadId);
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 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 phone code is already existing 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.leadId,update_phone_no_map);
}
}
}
Notes
- This function avoids adding the country code if the phone number is blank and prevents duplication if the number already has a prefixed country code.
- Map out all the countries and their corresponding codes from where your leads will contact your business.
- Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more
Tips
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Go to Leads > +Create Lead.
- Enter the lead information, their country, and their phone number without the country code.
- Click Save.
The workflow rule will be triggered. - Check whether the lead's phone number field gets updated with the country code corresponding to its country field value.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleLeads
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST