Updated the business rules.   Here's the latest versions of both.



/****************************************************************************


Create SMS Notification Device



This Business Rule creates a primary SMS notification device based off the


Mobile phone (sys_user.mobile_phone) and Carrier (sys_user.u_carrier) fields.



Type of Script:   Business Rule (after)


Location:   User Table [sys_user]



David Hoffman


Created 10/17/14.   Last modified 10/30/14.


*****************************************************************************/



// Using Filter Conditions (Eureka+) on "When to run" tab instead of Script Condition on "Advanced" tab:


// Mobile phone is not empty AND


// Carrier is not empty AND


// Mobile phone matches regex /[(]?(\d{3})[\s]?[\-.\/\s)]?[\-.\/\s]?[\s]?(\d{3})[\s]?[\-.\/\s]?[\-.\/\s]?[\s]?(\d{4})[.]?/g;


//


// Originally used Script Condition field:   !current.mobile_phone.nil() && !current.u_carrier.nil()



var thisSysID = current.sys_id;


var device = new GlideRecord('cmn_notif_device');


device.user = thisSysID;


device.active = true;


device.name = 'Mobile Phone ' + current.mobile_phone.replace(regexUSA_CAN, "$1-$2-$3");


device.type = 'SMS';



// Regular Expression for USA/Canadian phone numbers in format 999-999-9999, 999.999.9999, (999) 999-9999, etc.


var regexUSA_CAN = /[(]?(\d{3})[\s]?[\-.\/\s)]?[\-.\/\s]?[\s]?(\d{3})[\s]?[\-.\/\s]?[\-.\/\s]?[\s]?(\d{4})[.]?/g;


if (regexUSA_CAN.test(current.mobile_phone)) { device.phone_number = current.mobile_phone.replace(regexUSA_CAN, "$1$2$3"); }



device.service_provider = current.u_carrier;


device.insert();


gs.addInfoMessage(gs.getMessage('SMS Notification Device created for ') + GlideStringUtil.escapeHTML(current.name) +


    ' - ' + GlideStringUtil.escapeHTML(current.mobile_phone.replace(regexUSA_CAN, "$1-$2-$3")));






/****************************************************************************


Update SMS Notification Device



This Business Rule updates a primary SMS notification device based off the


Mobile phone (sys_user.mobile_phone) and Carrier (sys_user.u_carrier) fields.



Type of Script:   Business Rule (after)


Location:   User Table [sys_user]



David Hoffman


Created 10/20/14.   Last modified 10/30/14.


*****************************************************************************/



// Using Filter Conditions (Eureka+) on "When to run" tab instead of Script Condition on "Advanced" tab:


// Mobile phone changes OR


// Carrier changes OR


// Notification changes


//


// Originally used Script Condition field:   current.mobile_phone.changes() || current.u_carrier.changes() || current.notification.changes()



var thisSysID = current.sys_id;


var device = new GlideRecord('cmn_notif_device');


device.addQuery('user', thisSysID);


device.addQuery('type', 'SMS');


device.query();



while (device.next()) {


    if (current.mobile_phone.changes()) {


              // OUTSTANDING "NICE TO HAVE" TO DO:   If the user doesn't have an existing SMS Notification Device, create one.


//               if (!device) {


//                     gs.addInfoMessage(gs.getMessage('No existing SMS Notification Devices.   Creating one.'));


//               }


           


              // Regular Expression for USA/Canadian phone numbers in format 999-999-9999, 999.999.9999, (999) 999-9999, etc.


              var regexUSA_CAN = /[(]?(\d{3})[\s]?[\-.\/\s)]?[\-.\/\s]?[\s]?(\d{3})[\s]?[\-.\/\s]?[\-.\/\s]?[\s]?(\d{4})[.]?/g;


           


              // Use the above regular expression to test if the Mobile Phone is a valid phone number.


              if (regexUSA_CAN.test(current.mobile_phone)) {


                    device.phone_number = current.mobile_phone.replace(regexUSA_CAN, "$1$2$3");


                    device.name = 'Mobile Phone ' + current.mobile_phone.replace(regexUSA_CAN, "$1-$2-$3"); // Update the SMS Notification Device name with new number.


                    device.active = true;


              }


           


              // If the Mobile Phone does not match the above regular expression, consider it an invalid number.


              else if (!regexUSA_CAN.test(current.mobile_phone)) {


                    device.phone_number = '';   // Blank out device number since invalid number.


                    device.name = 'Mobile Phone (Inactive)';


                    device.active = false; // Inactivate device since invalid number.


              }


      }


 


    if (current.notification.changes()) {


          if (current.notification == 2) { // If Notification drop down is set to "Enable"


                device.active = true;


          }


          else {                                                       // If Notification drop down is set to "Disable"


                device.active = false;


          }


    }


 


    if (current.u_carrier.changes()) {


          device.service_provider = current.u_carrier;


    }



 


    device.setWorkflow(false);


    device.update();


    gs.log('Updating ' + current.name + 's SMS Notification devices based on change to user record Mobile phone, Carrier or Notification field');


 


    if (current.mobile_phone != '') {


          gs.addInfoMessage(gs.getMessage('SMS Notification Device updated for ') + GlideStringUtil.escapeHTML(current.name) +


                ' - ' + GlideStringUtil.escapeHTML(current.mobile_phone.replace(regexUSA_CAN, "$1-$2-$3")));


    } else {


          gs.addInfoMessage(gs.getMessage('SMS Notification Device inactivated for ') + GlideStringUtil.escapeHTML(current.name));


    }



}