Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using Recipient List to populate Notification recipients

OWelch
Tera Contributor

Hi all, 

We use a Recipient List to dynamically build our Major Incident recipients, this works great within Task Communications Management. The recipient list is added to the email client template when sending Comms for a P1/P2. 

What I want to achieve is to be able to use this Recipient List (sn_publications_recipients_list) in standard Notifications (sysevent_email_action). For further context, I want to use this RL in Change Management. When a change is scheduled, I want an auomtated email sent with a summary of the change details to this list (hence notification with conditions). 

In notifications theres no simple UI option to add a RL, you can only add Users/Groups. So I've tried using a mail script to query the list, and to add the comma seperated email addresses to the To field of the notification. The mail script is placed in the Email Template the notification uses. Is this method even possible? Is this script correct?

 
(function() {

    var emails = [];

    var gr = new GlideRecord('sys_publication_recipients_list');
    gr.addQuery('list', 'dce37463fb9d96106e3ef92abeefdccc');
    gr.query();

    while (gr.next()) {
        if (gr.user.email) {
            emails.push(gr.user.email.toString());
        }
    }
    if (emails.length > 0) {
        template.print('${mail_add_recipients:' + emails.join(',') + '}');
    }

})();


The notification is sending, but there are no recipients added. Beyond this, the only other options I see is to create a sys_user_group from the RL (via a BR?) and add that. 

Thanks in advance!

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@OWelch 

share some screenshots.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

Here's my Recipient List:

Here user.email is available

OWelch_0-1764584137563.png

 

In my notification I can only add the following users and groups as recipients. I've left this empty in case this was conflicting with the mail script:

OWelch_2-1764584289587.png

 

So my mail script from original post is inserted here, within the Email Template:

OWelch_1-1764584247966.png

When I trigger the notification (which is simply Change Request state changes to Scheduled), no email is sent, as presumably there are no recipients. If I add add a user to "Who will Receive", the notifications works fine.