Issue
There are two field types: "Phone Number" and "Phone Number (E164)" to use phone numbers on the platform.
"Phone Number" is a legacy data type which inherits from String whereas "Phone Number (E164)" is the newer data type that provides richer functionalities and supports phone numbers in multiple country codes. We suggest users use the newer data type whenever they want to add a custom phone number field in a table.
Based on business requirements users may want to show the phone number in their local format in the instance.
Resolution
For the old "Phone Number" data type
The phone number format for this field is controlled by a client script. By default, it only supports phone numbers in local format for some western countries.
Follow these steps to customize this script to show the phone number in the local format of your own country.
For example, users in Japan enter "334561234" in the field and hope it will be converted to "(03) 3456-1234" in Japan local format automatically.
Steps:
- Navigate to the sys_ui_script.list table
- Create a new UI script record with this information:
- API Name = formatting.js (Or any preferred name)
- UI Type = Desktop
- Active = true
- Open this client script copy it into the newly created record:
- https://<instance-name>.service-now.com/scripts/formatting.js
- Modify line 16 in the script as follows:
- from: else if (n == 3)
- to: else if (n == 2)
- Save the UI script record
For the new "Phone Number (E164)" data type
The phone number format for this data type is controlled by system property "glide.phone_number_e164.display_national".
This system property provides 3 values, all, user and false, to control the phone number format.
- false: the system does not display phone numbers in local format (phone number will be displayed with a country code in the front)
- all: the system always displays phone numbers in a local format no matter which country is selected
- user: the system only displays phones number in a local format when the local settings of the currently logged-in user match the country that is selected in the country list of this "Phone Number (E164)" field.
Related Links
If users apply the solution in formatting.js for the old "Phone Number" field, please be aware that users need to own that code from now on as it has been customized.
For more detailed information: E.164 phone number field configuration