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

Harish KM
Kilo Patron
Kilo Patron

Hi @Oliver Anderson can you correct the answer arrayto

answer.push(gr.user.sys_id.toString());

Regards
Harish

Thanks for the suggestion, but it is still only sending one email to the last sys_id in the array (logs look exactly the same as in the original post).

Hi @Oliver Anderson I tested in PDI works fine for me. I am using Approval User activity

HarishKM_0-1710811199766.png

 

answer = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', 'b85d44954a3623120004689b2d5dd60a');
gr.query();

while (gr.next()) {
answer.push(gr.user.sys_id.toString());
}

HarishKM_1-1710812461586.png

Also you can use approval group activity to send email to all users within a group like below, no script required

HarishKM_2-1710812558458.png

 

Regards
Harish

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