- 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-19-2024 06:42 AM
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 😑