Email a list of subscribed users

Cirrus
Kilo Sage

Hi,

Hopefully this is just me being a scripting novice.

We require the ability to send bespoke notifications to users subscribed to particular service offerings, and have created a catalog item where the service manager can select the offering and compose the email. Upon submit, a create event activity in the workflow should query the subscription table for each occurrence of that offering, and get the subscribed users email to pass as parameter 1. However, its currently only generating 1 email with no recipients, where there should be 7. Can anyone advise what we are doing wrong please. Script as it stands currently:

 

(function() {
   
var serv = new GlideRecord('service_subscribe_sys_user');  
serv.addQuery('service_offering','40c3aeb0974f2550063c7e371153affb');
serv.query();

while(serv.next()){
serv.getValue('email')
var mail = serv.toString();
    return mail;
}
}());

 

6 REPLIES 6

Anand Kumar P
Giga Patron
Giga Patron

Hi @Cirrus,

(function() {
var serv = new GlideRecord('service_subscribe_sys_user');
serv.addQuery('service_offering', '40c3aeb0974f2550063c7e371153affb');
serv.query();

while (serv.next()) {
var mail = serv.getValue('email');
gs.info('Sending email to: ' + mail);

mail.addAddress('cc', mail)
}
})();

Mark it helpful and solution proposed if it serves your purpose.

Thanks,

Anand

 

Anand,

Have amended the script but still only getting 1 email and no recipient

 

(function() {
   
var serv = new GlideRecord('service_subscribe_sys_user');  
serv.addQuery('service_offering','40c3aeb0974f2550063c7e371153affb');
//serv.getValue('email')
serv.query();

while(serv.next()){
var mail = serv.getValue('email');
return mail;
}
}());

Community Alums
Not applicable

You should be returning list of sys_id's or emails. So try this approach:

(function() {
var myArr = [];   
var serv = new GlideRecord('service_subscribe_sys_user');  
serv.addQuery('service_offering','40c3aeb0974f2550063c7e371153affb');
//serv.getValue('email')
serv.query();

while(serv.next()){
var mail = serv.getValue('email');
//I'd go that way though - myArr.push(serv.getValue("email")); but and the below will do 
myArr.push(mail);
}

return myArr.toString();
}());

Thanks Joro, but as with Anands approach still only getting one email and no recipients, when what I actually want is to send one email 7 times to the 7 different subcribers