Telephone Number Formatting
Hi, Following on from the April digest, here is a custom function, that Ive got in place for UK based +44 numbers
- contact = zoho.crm.getRecordById("Contacts", contact_id);
- // Get ONLY the Phone field.
- phone_number = contact.get("Phone");
- // If phone_number isn't null...
- if (!isnull(phone_number)) {
- info "Original phone number: " + phone_number; // Log the original value
- // Remove spaces
- phone_number = phone_number.replaceAll(" ", "");
- // Replace 01, 02, 07, 0044, +440 or 44 with +44 directly
- if (phone_number.startsWith("01") || phone_number.startsWith("02") || phone_number.startsWith("07")) {
- phone_number = "+44" + phone_number.substring(2);
- } else if (phone_number.startsWith("0044") || phone_number.startsWith("+440")) {
- phone_number = "+44" + phone_number.substring(4);
- } else if (phone_number.startsWith("44")) {
- phone_number = "+" + phone_number; // Simply add the "+" sign at the beginning
- }
- info "Modified phone number: " + phone_number; // Log the modified value
- // Update ONLY the Phone field if a replacement was made.
- if (phone_number != contact.get("Phone")) {
- phone_update = Map();
- phone_update.put("Phone", phone_number);
- zoho.crm.updateRecord("Contacts", contact_id, phone_update);
- } else {
- info "No update needed. Phone number is already in the correct format.";
- }
- } else {
- info "No phone number found for this contact.";
- }