The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to set value in "Phone Number(E164)" field via script

peter_repan
Tera Guru

Hello community,

I have created field with type "Phone Number(E164)". By default, this field has territory picker and auto-check for correct number format.

I would like to pre-populate this field via script using:

g_form.setValue('u_phone_number', myValue);

but for some reason this is not working. Now I realized that one approach could be through standard javascript:

document.getElementById('input_field_id').value = myValue;

Do you have any other idea / explanation why g_form.setValue('...') is not working and if I can use any other OOB function?

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Peter,



You may find the below link helpful.


Getting country from Phone Number (E164) field in a script?


Hi Pradeep,



your link is about getting the value on server side. I would like to set the value on the client...


JasonHamlin
Kilo Explorer

I am having the exact same problem with updating the phone number from a client script OnChange event. We are on Eureka Patch 11. I set the phone number (E164) field based upon the Contact Name changing and with setValue it doesn't change it at all. Then I tried document.getElementById and that *looks like* it changes the value on the screen, however it doesn't save with that value. Here's my code:



g_form.setValue('u_phone_number', contact.phone); // Doesn't work at all.


document.getElementById('disp_u_record_requests.u_phone_number').value = contact.phone; // Changes the value on the screen, but still won't save with the new value.



Any ideas from the community would be greatly appreciated.


We ran into similar issues while trying to transform map phone numbers into a e164 field.



Check the value you are passing to u_phone_number, make sure it is all numeric. In my case there were parentheses, hyphens, spaces etc. I had to strip all of that and prefix it with + country code. Also try turning off the glide.phone_number_e164.strict system property. If it is absent or set to true, the numbers must match the country code.