- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:29 AM
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:
Email log:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 06:54 PM
Hi @Oliver Anderson,
Can't you use the 'To (groups)' field instead of a script?
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:34 AM
Hi @Oliver Anderson can you correct the answer arrayto
answer.push(gr.user.sys_id.toString());
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:39 AM
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).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 06:41 PM - edited 03-18-2024 06:42 PM
Hi @Oliver Anderson I tested in PDI works fine for me. I am using Approval User activity
answer = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', 'b85d44954a3623120004689b2d5dd60a');
gr.query();
while (gr.next()) {
answer.push(gr.user.sys_id.toString());
}
Also you can use approval group activity to send email to all users within a group like below, no script required
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 06:54 PM
Hi @Oliver Anderson,
Can't you use the 'To (groups)' field instead of a script?
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