How can I send a notification to SMS devices only?

Casey23
Tera Guru

We have a workflow with hardcoded SMS numbers via the Notification workflow activity. Anytime someone joins/leaves the organization (that is part of this process), the workflow needs to be modified and its a pain to manage.

 

Ideally, we would be able to send a notification to a group so we can just add/remove members as necessary. However, based on what I've been seeing on community, it's not looking like this is possible since you have to ensure users have the notification message set to go to their SMS device. Either way that's better than managing it in the workflow.

 

What I've done so far is created an event in the event registry, and replaced the notification activity with a "create event" activity. I then created a notification that fires when the event is triggered. I went to my user record and validated that the notification shows up under the "Notification Messages" related list and is set to go to my mobile device. However, when I execute the workflow and validate that the event was triggered (in the event log), I'm not seeing the SMS in the email logs. I think the disconnect is that even though I have the notification message setup to go to my mobile device the notification itself doesn't have any recipients. This is because adding recipients triggers an email to the users email address, and not to their SMS device.

 

This is what my notification looks like: 

Casey23_0-1742325875029.png

Casey23_1-1742325891264.png

Casey23_2-1742325949798.png

Casey23_3-1742325971893.png

The only thing that I didn't do from the following article is the part about making it subscribable. We don't allow users to subscribe/unsubscribe from notifications out of ServiceNow. However, because it wasn't working, I did attempt this for testing purposes and it didn't help. https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0712569

 

Any thoughts on how to accomplish this, or what I might be missing here?

 

Again, I can see the event is triggering, and if I add a group as a recipient, the notification is sent to the email addresses for that group, I just want to send it to the SMS device only.

 

Thanks!

 

1 ACCEPTED SOLUTION

Casey23
Tera Guru

After some additional testing, it appears that the SMS message won't send unless you also have an email template with data in the "Message HTML" field, or the "Message HTML" field is filled out directly in the notification record.

 

This doesn't work for our scenario, because we are attempting to send an SMS message when approval is requested on an emergency change, and once that change is approved. Because notifications are already setup based on the approval being inserted, this would result in duplicate notifications. At least for the first one.

 

To work around this, I've implemented the following solution:

 

- Created a system property to store the various SMS numbers that we want to send to

- In the workflow, updated the "Notification" activity so that instead of populating the "To" field with SMS numbers directly, it uses the following script:

// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.
answer = [];
//getting the sms number from sys_properties.list
var erChange = gs.getProperty('name.of.property.here');
answer.push(erChange);

- Created a scheduled script execution to get the members of the group, search for their SMS devices, and populate the system property with the SMS numbers in order to keep the list of numbers up to date:

	var groupId = 'put the groups sys_id here'; // Group sys_id
    var masterSmsList = [];

	// Query the Group Members table to get members of the group
    var userGr = new GlideRecord('sys_user_grmember');
    userGr.addQuery('group', groupId);
    userGr.query();

    while (userGr.next()) {
        var userId = userGr.user.toString();
        var userName = userGr.user.name;
        var userSysId = userGr.user.sys_id.toString();

        //gs.info('User Name: ' + userName + ' SysId: ' + userId);

        // Get the SMS number for each of the users in the group
        var smsGr = new GlideRecord('cmn_notif_device');
        smsGr.addQuery('user', userSysId);
        smsGr.addQuery('type', 'SMS');
        smsGr.query();

        while (smsGr.next()) {
            masterSmsList.push(smsGr.email_address.toString());
        }

        //gs.info('SMS Addresses: ' + smsList.join(', '));
    }
    // Log the list of numbers
    //gs.info('All SMS Addresses: ' + masterSmsList.join(','));

    var propertyName = 'name.of.property.here'; // Property that contains the SMS numbers
    var masterSmsString = masterSmsList.join(',');

	// Update the system property with the queried SMS numbers
    var sysPropGr = new GlideRecord('sys_properties');
    sysPropGr.addQuery('name', propertyName);
    sysPropGr.query();

    if (sysPropGr.next()) {
        sysPropGr.value = masterSmsString;
        sysPropGr.update();
        //gs.info('Updated sys_property ' + propertyName + ' with: ' + masterSmsString);
    } else {
        //gs.warn('sys_property ' + propertyName + ' not found.');
    }

 

View solution in original post

5 REPLIES 5

Shivalika
Mega Sage

Hello @Casey23 

 

Have you checked the SMS Alternate box ? 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwN

eEISQCY

Yes, the SMS alternate field is populated.

Casey23
Tera Guru

Just bumping this to see if anyone has any input. I can test other notifications in our system to confirm that the system is sending to SMS addresses, but we don't have any based specifically on an event. They are usually based on conditions after an insert/update.

Casey23
Tera Guru

If I add text to the Message HTML field, it does send both an email and a text message. But in this case, a different email notification for this event is already being sent, because an approval is being inserted. So ideally I'd only want to send an SMS.