Phone number fields

George Scholl
Tera Expert

Pretty simple question, but it has me stumped.  I need to move a user's phone number to a single line text variable.  How do I do that ? 

 

g_form.setValue('telephone', usr.phone);  doesn't work.  Seems like have to do with the users phone number field is set up a 'phone number' and there is no variable type for phone number.   I have location working fine,  g_form.setValue('location', usr.location); 

2 ACCEPTED SOLUTIONS

Brad Bowman
Kilo Patron
Kilo Patron

Have you tried forcing it to a string?

g_form.setValue('telephone', usr.phone.toString());

 

View solution in original post

Thanks Brad, that worked !

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Have you tried forcing it to a string?

g_form.setValue('telephone', usr.phone.toString());

 

Thanks Brad, that worked !

khanariyan
Kilo Contributor

 

Since the phone number field in ServiceNow (or similar platforms) is set up as a "phone number" type, it's not just a simple text field and might have some additional formatting or validation that prevents g_form.setValue('telephone', usr.phone) from working as expected.

To move the phone number to a single-line text variable, you can try converting the phone number value into a string and removing any non-numeric characters (like parentheses or hyphens) before setting it to the text field. Here’s how you could do it:

 

javascript
Copy
var phone = usr.phone.replace(/\D/g, ''); // This will remove non-numeric characters g_form.setValue('telephone', phone);
 

This way, you'll store the phone number in a plain format without any special characters, which should allow it to work with a single-line text field.