- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2014 02:03 PM
Out of the Box, ServiceNow automatically creates an e-mail notification device called "Primary email" from the sys_user.email field. Is there a way to do the same thing for cell phones? I have sys_user.mobile_phone automatically pulled in through Active Directory LDAP integration, as simply the user's mobile phone number: 123-456-7890. I'd like a way for this to automatically create an SMS device for each user instead of having to manually maintain this for the ~200 or more IT workers who need to be paged out for Severity 1 or 2 incidents and any other SMS notification.
Is this as simple as creating an LDAP onAfter transform script to map sys_user.mobile_phone --> cmn_notif_device table?
Pseudocode as follows:
if (this person doesn't already have a notification device corresponding to their mobile_phone) { var person = source.u_samaccountname.toString() + " (" + source.u_givenname.toString() + " " + source.u_sn.toString() + ")"; cmn_notif_device.name = "Bob's Mobile Phone"; // or whatever name I wish to call it cmn_notif_device.type = "SMS"; // (use regular expression to strip out punctuation so 123-456-7890 becomes 1234567890). cmn_notif_device.phone_number = sys_user.mobile_phone; cmn_notif_device.service_provider = "Verizon" / "T-Mobile" / "Sprint" / "AT&T" // (etc.) log.info("Creating new SMS Notification Device for " + person); }
or would this be done as a Business Rule somewhere?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2014 04:32 PM
Hi, David. You could use a transform script but it might be easier to make a business rule on the user table. The primary notification device is created by a business rule on the user table called 'Create primary email device' so you could just copy that and change it to create the cell device record.
The only issue is that you need to know who the provider is for each user because that is required on the notification device record. If that information is available through your LDAP integration and you aren't storing it on the user record then you may need to use a transform script since that would be the only time the provider information is available. But the script from the business rule would still provide a starting point for a transform script.
Hope this helps.
Thanks.
- Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2014 04:32 PM
Hi, David. You could use a transform script but it might be easier to make a business rule on the user table. The primary notification device is created by a business rule on the user table called 'Create primary email device' so you could just copy that and change it to create the cell device record.
The only issue is that you need to know who the provider is for each user because that is required on the notification device record. If that information is available through your LDAP integration and you aren't storing it on the user record then you may need to use a transform script since that would be the only time the provider information is available. But the script from the business rule would still provide a starting point for a transform script.
Hope this helps.
Thanks.
- Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2014 12:30 PM
Thanks Steve. Your suggestion to use a Business Rule is definitely the way to go and a best practice. (And would be neat to have this out-of-the-box in Fuji/Geneva!).
In designing this, I wanted to have the best of all worlds; meaning, I'd like the flexibility for this process to work on automatic LDAP integration as well as manual bulk import from Excel, as well as let the user change their mobile_phone field on their User Profile and have it also work.
I created 2 Business Rules on the User form <sys_user> as suggested and modeled them after the out-of-the-box E-mail Device Business Rules:
1) Create SMS Device
2) Update SMS Device
I also created a "Carrier" string field on the User <sys_user> table and made it a Choice list with Verizon, T-Mobile, AT&T, Sprint, etc. choices. And a Global UI Policy that if Mobile phone (sys.user.mobile_phone) is empty to also hide the Carrier field (and reverse if false).
In case this helps the Community, here are more details.
1) Create SMS Device
Table: sys_user
When: after
Order: 100
Checkboxes: After, Advanced, Insert
On Advanced tab, set Conditions to: !current.mobile_phone.nil() && !current.u_carrier.nil()
to make sure that both fields are populated on insert of a new user record.
/****************************************************************************
Create Primary 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
Location: User Table [sys_user]
Created 10/17/14. Last modified 10/20/14.
*****************************************************************************/
// Caveats:
// 1) If Carrier is blank, don't execute Business Rule.
// Set Condition to: !current.mobile_phone.nil() && !current.u_carrier.nil()
// 2) If phone number is not 1234567890, don't execute Business Rule. (done via regex)
var thisSysID = current.sys_id;
var device = new GlideRecord('cmn_notif_device');
device.user = thisSysID;
//device.primary_email = true; Not applicable to SMS devices (True/False record doesn't exist.)
device.active = true;
device.name = 'Mobile Phone ' + current.mobile_phone;
device.type = 'SMS';
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('Primary SMS device created for') + ' ' + GlideStringUtil.escapeHTML(current.name));
2) Update SMS Device
Table: sys_user
When: after
Order: 100
Checkboxes: After, Advanced, Update
On Advanced tab, set Conditions to: current.mobile_phone.changes() || current.u_carrier.changes() || current.notification.changes()
NOTE: The Update Business Rule is currently buggy. If you change "Carrier" to "Verizon" for example, it'll create a 2nd entry for Verizon on the Notification Device (cmn_notif_service_provider).
/****************************************************************************
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
Location: User Table [sys_user]
Created 10/20/14. Last modified 10/20/14.
*****************************************************************************/
//Condition: 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 (device.primary_email == true)
// device.email_address = current.email;
if (current.notification.changes()) {
if (current.notification == 2)
device.active = true;
else
device.active = false;
}
device.name = 'Mobile Phone ' + current.mobile_phone;
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;
gs.log('Updating ' + current.name + 's SMS Notification devices based on change to user record mobile phone or Notification field');
gs.addInfoMessage(gs.getMessage('Primary SMS device updated for') + ' ' + GlideStringUtil.escapeHTML(current.name));
device.setWorkflow(false);
device.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2014 12:52 PM
Outstanding issues:
1) If we want to fully automate this via LDAP Integration (Active Directory), need some way to put into AD what carrier the "mobile" attribute corresponds to. Can possibly use extensionAttribute field. Otherwise, the Carrier (sys_user.u_carrier) field will have to either be manually modified via the GUI or via a bulk data load from Excel/CSV file to the sys_user table.
2) The "Update SMS Device" Business Rule has a bug where if the carrier is changed, it will create duplicate records.
I think this line is probably too basic:
device.service_provider = current.u_carrier;
If the Carrier is changed to Verizon, T-Mobile, etc, it'll successfully map to device.service_provider, but that field (cmn_notif_device.service_provider) is actually a Reference field to cmn_notif_service_provider which has the details for SMS/SMTP construction (e.g. Verizon --> number@vtext.com)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2014 01:26 PM
I have been thinking about doing the same action as this thread discusses and regarding item one we were looking at extending our LDAP table. Another item I am investigating is if I could get the information from our Mobile device management suit perhaps by a web service call. I would like to use the SMS features but need to populate all the information as being discussed in this thread. Timely post!