Adding members of a group to Notification Bcc field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 05:51 AM
We have been tasked with notifying a group when a new article is created. However, it is required that those users in the group cannot see each others email and cannot respond to each other, so i was thinking on adding them to the Bcc field. So far I have the notification working, an email template for said notification and am working on an email script that is being called in the template itself. I have tested that the script is successfully being called by the template. I have also tested the script in the background and am seeing the results i expect. However, when I prompt the notification it is not adding users to the Bcc as i expected. Below is the current code i have the for the script:
//getting Group sys_id
var usergroup = new GlideRecord("sys_user_group");
usergroup.addEncodedQuery('name=admin test group');
usergroup.query();
var sysid = usergroup.sys_id;
while (usergroup.next()) {
gs.info("This is with it as a var" + sysid);
}
var memberlist = new GlideRecord("sys_user_grmember");
memberlist.addQuery("group", sysid);
memberlist.query();
while (memberlist.next()) {
//gs.info("The user id is: " + list.user);
var userid = memberlist.user;
var groupuser = new GlideRecord("sys_user");
groupuser.addQuery("sys_id", userid);
groupuser.query();
while (groupuser._next()) {
//gs.info("user email is: " + groupuser.email);
email.addAddress("bcc", groupuser.email, groupuser.getDisplayValue());
}
}
When i run this in the background using the gs.info call above i can see the email addresses of each member without issue but when i do the actual notification it doesnt work.
note if i Hardcode an email addess in for the Bcc in the above code it does work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 05:57 AM
I think it's a simple formatting error...
This:
while (groupuser._next()) {
_next?
try
while (groupuser.next()) {
Also, you can post your code using the "Insert/Edit code sample" button...which makes things look a bit more organized and easier for us to read.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 05:59 AM
Hi Austin,
Please try this script:
var usergroup = new GlideRecord("sys_user_group");
usergroup.addEncodedQuery('name=admin test group');
usergroup.query();
var sysid = usergroup.sys_id;
while (usergroup.next()) {
gs.info("This is with it as a var" + sysid);
}
var memberlist = new GlideRecord("sys_user_grmember");
memberlist.addQuery("group", sysid);
memberlist.query();
while (memberlist.next()) {
//gs.info("The user id is: " + list.user);
var userid = memberlist.user;
var groupuser = new GlideRecord("sys_user");
groupuser.addQuery("sys_id", userid);
groupuser.query();
while (groupuser.next()) {
//gs.info("user email is: " + groupuser.email);
email.addAddress("bcc", groupuser.email, groupuser.getDisplayValue());
}
}
Kindly mark the answer Correct and Helpful if this answers your question.
Thanks,
Ali.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 06:32 AM
Thanks all for saying the same thing I did already, hah.
Anyways, Austin, let me know if that still doesn't resolve your issue, but I'm sure it's just a small formatting issue like I mentioned above.
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2020 01:59 PM
Hi,
It's been a bit since my reply was posted. I just wanted to check-in and see how things are going.
If my reply helped guide you correctly, please mark it as Helpful & Correct.
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!