How to get email addresses of business owners from business services list collector variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi,
We have a list collector variable on catalog item referenced to Business Applications table (cmdb_ci_business_app). Need to get the email addresses of business owners of business applications selected on the variable on the notification script so that we can add that to recipients list on notification.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var emailList = [];
var appList = current.variables.bus_app + ',';
if (appList) {
var appGR = new GlideRecord('cmdb_ci_business_app');
appGR.addQuery('sys_id', 'IN', appList);
appGR.query();
while (appGR.next()) {
var owner = appGR.owned_by;
if (owner && owner.email) {
var emailAddress = owner.email.toString();
if (!emailList.includes(emailAddress)) {
emailList.push(emailAddress);
}
}
}
}
for (var i = 0; i < emailList.length; i++) {
emailAddress.addAddress('to', emailList[i]);
}
})(current, template, email, email_action, event);
And called that notification script on notification with below
${Mail Script: get_business_owners}
It is not working. Can anyone please assist?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
hi @sath
May you try this solution
${mail_script:get_business_owners}
(function() {
var emailList = [];
var appList = current.variables.bus_app;
if (appList) {
var appGR = new GlideRecord('cmdb_ci_business_app');
appGR.addQuery('sys_id', 'IN', appList);
appGR.query();
while (appGR.next()) {
var emailAddress = appGR.owned_by.email.toString();
if (emailAddress && !emailList.includes(emailAddress)) {
emailList.push(emailAddress);
}
}
}
template.print(emailList.join(', '));
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @sath
is the mail script even triggered? Add there some logs to see what’s happening or not :))
I don’t think the syntax is correct:
${Mail Script: get_business_owners}
can you try ${mail_script: get_business_owners} ?
also, the notification record is applied on what table? The recipients can be dot-walked so perhaps it is doable without a single line of code.
last but mot least, you can create an event and fire it when you need and part of the event it can be the email received by a simple glide record..
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */