Email a list of subscribed users

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2023 05:11 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2023 05:29 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2023 06:27 AM
Anand,
Have amended the script but still only getting 1 email and no recipient
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2023 07:04 AM
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();
}());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2023 07:25 AM
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