
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 03:48 AM
Hi All,
I am trying to include users who are part of a field (Users & Non-Users) into the cc (copied) field using the email script but my script only adds the users from sys_user table and non-users are excluded. Please let me know a way to combine users plus non-users
With the below script if I have three email ids (one part of user table) and two non-users only user is added to copied field in the notification. How to include the non-users as well
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
if (!current.trigger_id.u_string_7.nil()) {
var tbl = current.trigger_table;
var sysID = current.trigger_id;
var ccIds = current.trigger_id.u_string_7.split(",");
var user = new GlideRecord("sys_user");
user.addQuery("email", ccIds);
user.query();
while (user.next()) {
email.addAddress("cc", user.email, user.getDisplayValue());
}
}
})(current, template, email, email_action, event);
Appreciate your response.
Thank You,
Imran
Solved! Go to Solution.
- Labels:
-
Notifications

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 08:02 AM
Hey Imran,
Its working for me, where are you checking for copied list, update your list/form layout to bring "Copied" field.
var ccIds = ["suzette.devaughan@example.com", "aman123@test.com", "imran456@test.com"];
template.print(ccIds);
for (var emailIndex in ccIds) {
var user = new GlideRecord("sys_user");
user.addQuery("email", ccIds[emailIndex]);
user.query();
if (user.next()) {
email.addAddress("cc", user.email, user.getDisplayValue());
} else {
email.addAddress("cc", ccIds[emailIndex], ccIds[emailIndex]);
}
}
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 08:02 AM
Hey Imran,
Its working for me, where are you checking for copied list, update your list/form layout to bring "Copied" field.
var ccIds = ["suzette.devaughan@example.com", "aman123@test.com", "imran456@test.com"];
template.print(ccIds);
for (var emailIndex in ccIds) {
var user = new GlideRecord("sys_user");
user.addQuery("email", ccIds[emailIndex]);
user.query();
if (user.next()) {
email.addAddress("cc", user.email, user.getDisplayValue());
} else {
email.addAddress("cc", ccIds[emailIndex], ccIds[emailIndex]);
}
}
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 08:14 AM
Hi Aman,
It is working now, within the first script this was missing when added it worked
user.addQuery("email", ccIds[emailIndex]);
Could you please explain how this works - the below portion of the script
for (var emailIndex in ccIds) {
Thanks Again
Imran

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 08:17 AM
This works like foreach, emailIndex starts iterating from beginning to end of array "ccIds", and you can use this as index to fetch values from array at those indexes ie ccIds[emailIndex]
Aman Kumar