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.

Notification workflow activity only sending to one recipient

Oliver Anderson
Kilo Sage

I am trying to use a script on a notification workflow activity to send an email to the members of a particular group. When I try the script in background scripts, I am able to get all members of the group successfully, and when I add logging in the workflow activity I can see the group members in the answer variable, but email logs show only one email going out. Not sure what I'm doing wrong here.

Script:

// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.
answer = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', '72a201cf87bc02107631c956cebb35b3');
gr.query();
while (gr.next()) {
	gs.log(gr.user.name, 'noti_test');
    answer.push(gr.user.sys_id.getValue());
}
gs.log(answer, 'noti_test');

Script log:

OliverAnderson_0-1710772050879.png

Email log:

OliverAnderson_1-1710772115987.png

 

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hi @Oliver Anderson,

 

Can't you use the 'To (groups)' field instead of a script?

JamesChun_0-1710813181807.png

 

But in regards to the script, I believe the 'answer' variable needs to be a comma-separated list.

So, add the following line of script:

answer = answer.join(',');

 Cheers

View solution in original post

5 REPLIES 5

Going to accept this as solution because it was somewhat right! I started out by using the 'To (groups)' field but it wasn't working as expected. I just realized my problem is that the second user in the group has email notifications disabled..... always check user preferences 😑