How to get area code from 10 digit phone number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 08:29 AM
Hi Guys, I have a field 'office_phone' of type 'phone_number_e164'. When the field value is '+49 123 xxxxxxx, I would like to get '123' alone (basically to get area code). How to get this, because sometimes the number can be '+1 123 xxxxxxx'. Please suggest. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 08:44 AM
Please follow below steps.
1) Have the mapping of the Country and Country codes in a lookup table (could be country table itself).
2) Create an Onchange Catalog client script.
3) Pick the value of the country from country field, then pass it on to the server with glide ajax and then from server return the country code (through script include).
4) Use g_form.setValue to append the country code returned from server to the phone number field.
If my answer solved your issue, please mark my answer as👍 Correct &Helpful based on the Impact.
Chiranjeevi
ServiceNow Developer | | ITSM | | ServiceNow Discovery | | Event Management | | Service Mapping | | CMDB
Please mark as Correct Answer/Helpful, if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 09:04 AM - edited 11-10-2023 09:06 AM
@Praveen75 Simply use the following script to get the number.
var phoneNumber = '+49 123 xxxxxxx';
var phoneNum = phoneNumber.split(' ')[1];
gs.info(phoneNum.trim());
Please mark this answer helpful and correct if it addresses your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 01:01 PM
Minor comment: A better name for the variable above is areaCode instead of phoneNum, as the OP asked about just getting the area code in that format.