Phone number format for users

ahmed-24
Tera Expert

Hello Community,

I would like to change the format of the Mobile phone (mobile_phone) field in the User [sys_user] table.

Currently, the phone numbers are displayed in the following format:
Example: 1(449) 260-6439

However, I would like the numbers to be displayed and stored in a simple numeric format like:
Example: 06212348725

Requirement:

I want the Mobile phone number to:

  • Be displayed exactly as entered

  • Not automatically formatted with country code, parentheses, or dashes

  • Use a plain numeric format (example: 06212348725)

Althout i have disable the sys properties for us format but u still have the probleme  : 

 

 

ahmed24_0-1770732095288.png

Sys_properties : glide.ui.format_phone

ahmed24_2-1770732233610.png

 

Thank you for help 

 

13 REPLIES 13

Dr Atul G- LNG
Tera Patron

Hi @ahmed-24 

what is the use case  change data type of the Phone Number field. It is not recommended because this field is used in On-Call, FSM, and CSM as well. If it is changed to a string, users would be able to enter anything, which would not be the correct behavior.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

hello @Dr Atul G- LNG  

I would like to change the format of the Mobile phone (mobile_phone) field in the User [sys_user] table.

Currently, the phone numbers are displayed in the following format:
Example: 1(449) 260-6439

However, I would like the numbers to be displayed and stored in a simple numeric format like:
Example: 06212348725

Hi @ahmed-24 

What is the use case for converting this data type to a string? What are you trying to achieve by changing it?

Please consider that this field is not just a phone number field—it is used for on-call purposes, CSM, FSM, and other integrations where messages are sent to phone numbers. Changing the data type would disrupt all of these functionalities.

This data type is by design and serves a specific purpose, so it should not be changed. If you need additional flexibility, it would be better to create a new field and, through logic, convert it to a string and use it instead, rather than modifying the existing platform field.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Chaitanya ILCR
Giga Patron

HI @ahmed-24 ,

setting the system property (glide.ui.format_phone) to false is working for me

if you still facing the issue try clearing the cache or try to use a different browser or try incognito mode

 

if you are still facing the issue

try this

create a client script on sys_user table

 

 

ChaitanyaILCR_3-1770741091053.png

 

function onLoad() {
    if (g_form.hasField('mobile_phone')) {
        var mp = g_form.getValue('mobile_phone')
        if (mp) {
            g_form.setValue('mobile_phone', mp.replace(/[^0-9]/g, ""));
        }
        var mobilePhone = g_form.getControl('mobile_phone');
        mobilePhone.setAttribute('onChange', '');
    }


    if (g_form.hasField('phone')) {
        var phone = g_form.getValue('phone')
        if (phone) {
            g_form.setValue('phone', phone.replace(/[^0-9]/g, ""));
        }
        var phoneElement = g_form.getControl('phone');
        phoneElement.setAttribute('onChange', '');
    }
}

 

 

also you would have to run a fix script or Background script to fix the existing data

var userGR = new GlideRecord("sys_user");
userGR.addEncodedQuery("mobile_phoneISNOTEMPTY^NQphoneISNOTEMPTY");
// userGR.setLimit(10);
userGR.query();
while (userGR.next()) {

    var mp = userGR.getValue('mobile_phone')
    if (mp)
        userGR.setValue('mobile_phone', mp.replace(/[^0-9]/g, ""))
    var phone = userGR.getValue('phone');
    if (phone)
        userGR.setValue('phone', phone.replace(/[^0-9]/g, ""))

	userGR.update()
}

result

 

ChaitanyaILCR_4-1770741213510.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya