Adding members of a group to Notification Bcc field

Austin35
Kilo Explorer

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. 

6 REPLIES 6

Suseela Peddise
Kilo Sage

Hi,

Try updating the below line

while (groupuser.next()) { //remove _ from the line.

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.

Suseela Peddise
Kilo Sage

Hi,

As per your script, you are trying the code to add the 'admin test group' group members to bcc list of the email.

For this you no need to do use many GlideRecord queries. Instead of that try below:

Email Script:

var memberlist = new GlideRecord("sys_user_grmember");
memberlist.addQuery("group.name", 'admin test group'); 
memberlist.query();

while (memberlist.next()) {

 email.addAddress("bcc", memberlist.user.email, memberlist.user.getDisplayValue());

}

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.