
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 09:50 AM
I have a notification that is sent out each time an event/outage is created. Each event has one or more "Affected CI" that the event could pertain to. For each CI we have a support group (support_group) associated to it.
For each affected CI selected,I need to include the support group in the CC field of the notification.
FYI, Affected CI(u_affected_ci) is an list type field which references the "cmdb_ci" table. The event table is called "cmdb_ci_outage".
I have the below script and it is NOT adding the users to the CC field. I think I may have configure lines 26-28 incorrectly. Could someone look at my code and advice where changes should be?
Email Script
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
if (!current.u_affected_ci.nil()) {
//get all affected CI's as string separated by comma
var commaDelimetedAffectedCI = current.u_affected_ci.toString();
var affectedCiArray = commaDelimetedAffectedCI.split(',');
var userList = [];
//gs.addInfoMessage(commaDelimetedAffectedCI);
for(var i = 0; i < affectedCiArray.length; i++){
var apps = new GlideRecord("cmdb_ci");
apps.addQuery("sys_id", affectedCiArray[i]);
apps.query();
while (apps.next()) {
var supportGroup = apps.support_group;
//gs.addInfoMessage(supportGroup);
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery('group', supportGroup);
mem.query();
while (mem.next()) {
userList.push(mem.user.email.toString());
//gs.addInfoMessage(userList);
email.addAddress("cc", userList);
}
}
}
}
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 10:08 AM
user
while (mem.next()) {
//userList.push(mem.user.email.toString());
//gs.addInfoMessage(userList);
email.addAddress("cc", mem.user.email,mem.user.getDisplayValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 09:52 AM
hi,
you need to add display name as third paramter like below
email.addAddress("cc","john.secret@example.com","John Roberts");
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 10:08 AM
user
while (mem.next()) {
//userList.push(mem.user.email.toString());
//gs.addInfoMessage(userList);
email.addAddress("cc", mem.user.email,mem.user.getDisplayValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 10:01 AM
Can we try like, I don't think you need to push the users into an array.
if (!current.u_affected_ci.nil()) {
//get all affected CI's as string separated by comma
var commaDelimetedAffectedCI = current.u_affected_ci.toString();
var affectedCiArray = commaDelimetedAffectedCI.split(',');
//gs.addInfoMessage(commaDelimetedAffectedCI);
for(var i = 0; i < affectedCiArray.length; i++){
var apps = new GlideRecord("cmdb_ci");
apps.addQuery("sys_id", affectedCiArray[i]);
apps.query();
while (apps.next()) {
var supportGroup = apps.support_group;
//gs.addInfoMessage(supportGroup);
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery('group', supportGroup);
mem.query();
while (mem.next())
email.addAddress("cc", mem.user.email.totring(), mem.user.name.toString());
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 12:28 PM
Thank you both for your response. I'm going to mark Kumar response as correct since it worked for me
Thanks 🙂