Dynamically Setting Recipients List Based on On-Call Schedule

Community Alums
Not applicable

Requirement: Dynamically Setting Recipients List Based on On-Call Schedule to send out an SMS on the Major Incident Workbench.

 

Current Script: 

(function() {
    var currentTime = new GlideDateTime();
    var recipients = [];
    var groupSysId = current.assignment_group.sys_id;
    //var groupSysId = 'f71dfc0a1b2efc10c59b43f4bd4bcbdf';

    var onCallRotation = new global.OnCallRotationSNC();
    var rotationMembers = onCallRotation.getEscalatees(groupSysId);
    var userIds = rotationMembers.map(function(item) {
        return item.userId;
    });
    // gs.log(JSON.stringify(userIds));
    return {
        'internal': userIds
    };


})();

If I put in the static assignment group the script pulls in the correct sys_id of the users on-call. I'm having trouble identifying how to pull in the "Current" assignment group on my Dynamic Condition. Has anyone done this before?

3 REPLIES 3

FlorenceG
Tera Contributor

@Community Alums wrote:

Requirement: Dynamically Setting Recipients List Based on On-Call Schedule to send out an SMS on the Major Incident Workbench. Lowes Life

 

Current Script: 

 

(function() {
    var currentTime = new GlideDateTime();
    var recipients = [];
    var groupSysId = current.assignment_group.sys_id;
    //var groupSysId = 'f71dfc0a1b2efc10c59b43f4bd4bcbdf';

    var onCallRotation = new global.OnCallRotationSNC();
    var rotationMembers = onCallRotation.getEscalatees(groupSysId);
    var userIds = rotationMembers.map(function(item) {
        return item.userId;
    });
    // gs.log(JSON.stringify(userIds));
    return {
        'internal': userIds
    };


})();

 

If I put in the static assignment group the script pulls in the correct sys_id of the users on-call. I'm having trouble identifying how to pull in the "Current" assignment group on my Dynamic Condition. Has anyone done this before?


Hello,

It looks like you’re trying to dynamically set the recipients list based on an on-call schedule to send SMS notifications on the Major Incident Workbench in ServiceNow. Let’s break down the steps to achieve this:

Create an Email Notification:
First, create a standard email notification in ServiceNow.
Ensure that the message length in the email notification is within the SMS character limit (usually 140 characters) to avoid truncation.
Optionally, use the “SMS alternate” field in the Advanced view of the email notification to create a brief message specifically for SMS.
Create an SMS Service Provider:
Consult the documentation to create a service provider.
Make sure the service provider is active (check the “Active” box).
Troubleshoot any SMS notification issues by testing with an out-of-the-box (OOB) service provider. If the email notification triggers successfully, the issue likely lies with the SMS service provider configuration.
Create and Select an SMS Device for Users:
For specific users who should receive SMS notifications, create an SMS device if one doesn’t exist.
Use the following values when creating an SMS device:
Type: SMS
User: Select the sys_user record corresponding to the recipient.
Phone number: Enter the phone number where SMS notifications should be sent (format: <phone_number>@<SMS_Provider_Email_Suffix>).
Dynamic Condition for Recipients:
To dynamically set recipients based on the current assignment group, you’ll need to access the assignment group associated with the incident.
Unfortunately, directly referencing the “Current” assignment group in a dynamic condition isn’t straightforward.
Consider alternative approaches:
Script Include or Business Rule:
Create a script include or business rule that retrieves the current assignment group and returns the relevant user IDs.
Use this script include or business rule in your dynamic condition.
Custom Workflow or Scripted REST API:
Implement a custom workflow or a scripted REST API that fetches the on-call schedule and determines the recipients.
Call this workflow or API from your dynamic condition.
Scheduled Job:
Set up a scheduled job that periodically updates the recipients based on the on-call schedule.
Your dynamic condition can then reference the updated recipients.
Remember to adapt these steps to your specific use case and ServiceNow instance.


Hope this will help you.
Best regards,
FlorenceG

 

Community Alums
Not applicable

Thank you for your reply, however, I may have not explained my requirement well enough. In the Major Incident Management (MIM) module, I can already send out emails and SMS and I have confirmed this already works. What I am trying to do is utilize the OOTB recipients list through the Communication Plan Definition > Communication Task Definitions > Communication Channel Definitions> SMS to automatically assign the incidents assigned_to group to the outgoing recipients list (sn_publications_recipients_list ), however, it times out "refreshing the list". 

 

If I statically edit the recipients list, everything works flawlessly. 

Community Alums
Not applicable

Does anyone have any idea on this?