notification needs to be sent to users mentioned in variable

suuriya
Tera Contributor

HI Community,

 

I need to send notification to users mentioned in the variable.

In catalog item there is a variable set and the variable named notify (list collector) and refer to user table.... once the request is submitted with the user details in the notify field and when work notes/comments in catalog task are updated then notification needs to be sent to the users present in the notify variable.

 

How can we achieve this.

 

Thanks & Regards,

Suuriya Sridharan

2 REPLIES 2

Community Alums
Not applicable

Hi @suuriya ,

 

If  you want to add list of users in TO address then use event triggered notification as you can't directly dot walk from notification.

 

If  you want to add list of users in CC/BCC address then use event triggered notification as you can't directly dot walk from notification.

- Create a notification on Task table

Sai149_0-1716297090662.png

Add the below code in email script

var notifyVariable = current.variables.notify;
        if (notifyVariable) {
            var userIDs = notifyVariable.split(',');
            for (var i = 0; i < userIDs.length; i++) {
                var userID = userIDs[i].trim();
                var user = new GlideRecord('sys_user');
                if (user.get(userID)) {
                    email.addAddress("cc",user.email);
                }

 

Refer this link for more info

 https://www.servicenow.com/community/developer-forum/how-to-add-quot-to-quot-address-in-email/m-p/1361830 

 

I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

HS4
Tera Expert

Hi @suuriya ,

 

This is possible to achieve. Please register a new event using the Event Registry module. Trigger this event when your trigger condition is met, i.e. on catalog task update/ on req_item update. Create a notification and configure it to run when event is fired. Pass the targeted audience details via event parms to Notification.

 

E.g. Trigger event using the following code:

gs.eventQueue('event_name', current, parm1, parm2);

 

use either parm1/parm2 to pass recipient details, set parm1 = notify_variable, and leave parm2 as empty string, i.e. ''.

 

On the Notification record, check  'Event parm 1 contains recipient'.

HS4_1-1716298200277.png

 

 

If my answer helped you in any way, please then mark it as helpful or correct.

 

Thanks,