charleselite
ServiceNow Employee
ServiceNow Employee

With the introduction of Service Reliability Management it is easier than ever to onboard and automate your response to Incident with the on-call functions within SRM. Within SRM you can enable teams to on-board and manage their On-call schedules and response actions and deliver a great self-service experience.

 

The Team based On-Call management with SRM allows you on-board teams into SRM to remove bottlenecks at the central sys admin/IT team and give autonomy and independence to those SRM configure the systems with business logic and data specific to their teams, while central teams still want some level of governance.

 

SRM delivers an easy, and quick experience for admins to on-board the SRM plugin and add teams into the self-service model for On-call. Check it out here: ServiceNow On-call Scheduling in Service Operations Workspace Setup Demo (With Twilio) 

 

There is likely a extra step you need to take to ensure a high success rate with your newly setup integration with Twilio. That is ensure all your users have a Mobile Phone populated in the E164 format. The ServiceNow Sys_user table is not setup with these defaults.

 

How to automatically convert your user records to have E164 format

Just changing the field type to E164 is not enough to be successful. We'll likely need to format the numbers properly to work correctly.

 

1. For our use case we want to convert the data in the mobile_phone field on our sys_user table. Looking at my sample data set, we have numbers in various formats and we know the location of each user.

charleselite_0-1728508523133.png

 

 

2. We are going to need to run some data clean-up before converting the field type. We can do this systematically based on the county each user is in. Here is a closer look at the current state of our sample user Annabelle Coger who is located in France:

charleselite_1-1728508704099.png

 

3. Rather then line by line or asking end users to update this, we can quick execute a country code to re-format the data. Here is a sample script you can start your work with.

 

You will want to validate your cmn_location table country names to match the country code mapping and adjust this script as necessary.

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('mobile_phoneISNOTEMPTY^location!=NULL^ORDERBYname');
gr.query();
while (gr.next()) {
  var mobilePhone = gr.mobile_phone;
  if (mobilePhone) {
    var e164Phone = convertToE164(mobilePhone, gr.location.country);
    gr.mobile_phone = e164Phone;
    gr.update();
  }
}

function convertToE164(phoneNumber, location) {
  // remove all non-digit characters
  var cleanNumber = phoneNumber.replace(/[^0-9]/g, '');
  
  // country code mapping
  var countryCodes = {
    'India': '+91',
    'USA': '+1',
    'China': '+86',
    'Brazil': '+55',
    'United Kingdom': '+44',
    'France': '+33',
    'Japan': '+81',
    'Italy': '+39',
    'Germany': '+49',
    'Spain': '+34',
    'South Africa': '+27',
    'Thailand': '+66',
    'South Korea': '+82',
    'Mexico': '+52',
    'Portugal': '+351',
    'Australia': '+61',
    'Israel': '+972',
    'Russia': '+7',
    'Egypt': '+20',
    'Nigeria': '+234',
    'Pakistan': '+92',
    'Poland': '+48',
    'Vietnam': '+84',
    'Turkey': '+90',
    'Indonesia': '+62'
  };
  
  // determine country code based on location
  var countryCode = countryCodes[location.country] || '+1';
  
  // add country code if not already present
  if (cleanNumber.length == 10) {
    cleanNumber = countryCode + cleanNumber;
  }
  
  // format as E164
  var e164Number = '+' + cleanNumber;
  
  return e164Number;
}

 

4. After running the script I can see all the numbers are in the correct format and have the accurate country code

charleselite_2-1728508951137.png

 

5. Now I can update the Mobile Phone field to change the type to E164. Navigate to the dictionary entry for Mobile Phone and change type to Phone Number (E164)

charleselite_3-1728509070507.png

 

 

RESULT:

 

Your existing user records have been updated to the right format and have accurate phone numbers that are validated and ready to be used for on-call automation.

charleselite_4-1728509145072.png

 

1 Comment