Populate BCC of email client template

servicenow14710
Tera Expert

In catalog item based on a field lets say Services,  i need to populate BCC of email client template.

 

Services field has cmdb_ci_service table, where each Services i select has subscribed users.

So when i populate this field corresponding subscribed users has to be populated in BCC field.

Any suggestions.

Thanks.

2 ACCEPTED SOLUTIONS

Pravindra1
Tera Guru

Hi @servicenow14710 ,

 

- You can write an OnChange client script of catalog item field 'Services'.

- Then do a GlideAjax call within client script which will take input as selected Service and return the sys_id/email of all subscribed users.

Subscribed users against a CI is stored in "cmdb_subscriber" table. You can use below code in your script include to get subscribed users of CI.

var subscribedUsers = [];
var grUsers = new GlideRecord('cmdb_subscriber');
grUsers.addQuery('item', selectedService); //selectedService would be sys_id of selected service
grUsers.query();
while(grUsers.next()){
    subscribedUsers.push(grUsers.user); //it will store the comma separated sys_id of all subscribed users
    subscribedUsers.push(grUsers.user.email); // it will store the comma separated email of all subscribed users
}

 

- In callback function of GlideAjax, you can set the returned value to BCC field.

 

View solution in original post

Hi @servicenow14710 , If notification is being triggered from "sc_req_item" table then you can simply write an email script to add the subscribers email as below:

 

// To get the selected service CI subscribed users email
var grUsers = new GlideRecord('cmdb_subscriber');
grUsers.addQuery('item', current.variables.u_services); //u_services is here catalog variable name.
grUsers.query();
while(grUsers.next()) {
email.addAddress('bcc', grUsers.user.email.toString(), grUsers.user.name.toString()); //To Add email adress as bcc
}

Pravindra1_0-1683814006981.png

 

Then call your email script in Notification Template :
Pravindra1_1-1683814096824.png

 

 

 

 

View solution in original post

5 REPLIES 5

Hi @servicenow14710 , If notification is being triggered from "sc_req_item" table then you can simply write an email script to add the subscribers email as below:

 

// To get the selected service CI subscribed users email
var grUsers = new GlideRecord('cmdb_subscriber');
grUsers.addQuery('item', current.variables.u_services); //u_services is here catalog variable name.
grUsers.query();
while(grUsers.next()) {
email.addAddress('bcc', grUsers.user.email.toString(), grUsers.user.name.toString()); //To Add email adress as bcc
}

Pravindra1_0-1683814006981.png

 

Then call your email script in Notification Template :
Pravindra1_1-1683814096824.png