Created
December 15, 2017 10:06
-
-
Save CubeYogi/db4e028bff5587c7e04ef34b7ad4209e to your computer and use it in GitHub Desktop.
Zoho CRM Custom Function For Leads Phone Number Country Code Updation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Zoho CRM Custom Function For Leads Phone Number 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 Leads 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 Leads. | |
* Then this would update the 'Phone' field in the CRM Leads 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! ;) | |
* | |
*/ | |
/*This Function is to insert the Country Code for Phone Number (Based on the Country entered in Country Field) while creating a new Lead*/ | |
//Country & Phone extension Code Data Map | |
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 | |
if((input.phone != null) && (input.country != null)) | |
{ | |
//comparison to find the Phone extension Code on based on Lead Country | |
extension_code_to_add=data_set_extension_code.get(input.country); | |
if(extension_code_to_add != null) | |
{ | |
// appending the Phone extension Code based on Lead Country | |
input_phone_number="" + input.phone; | |
// removes leading zeros if exist | |
if(input.phone.toString().indexOf("0") == 0) | |
{ | |
input_phone_number=input.phone.toString().removeFirstOccurence("0"); | |
} | |
extension_to_assign=phone_number_sign + extension_code_to_add; | |
phone_no_to_update=extension_to_assign + input_phone_number; | |
//Comparison to check whether Extension Code is already Present in Phone Number | |
if(!startsWith(input.phone,phone_no_to_update) && !startsWith(input.phone,phone_number_sign)) | |
{ update_phone_no_map=map(); | |
update_phone_no_map.put("Phone",phone_no_to_update); | |
// Integration task to update Phone Number with Extension Code | |
update_phone_no_in_leads= zoho.crm.updateRecord("Leads","" + input.lead_id,update_phone_no_map); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment