
- 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 04:52 AM
Hey Imran,
Could you help me some more details here?
1. On which table you are building this?
2. What is "u_string_7" field?
3. ccIds will have 3 values, in your scenario(one user & 2 non user)
4. If there are two non user(which means they are not sys_user" table), why are you querying then with the email ids?
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 05:14 AM
Hi Aman,
Thank You for your response
I am trying to do this in assessment table.
u_string_7 is a string field that has email ids (comma separated)
ccIds in my example has 1 user and 2 non-users (not part of sys_user table) and this can vary
I need to combine users and non-users while adding them in the cc field. With user I would also require their names too (user.getDisplayValue()) does that
email.addAddress("cc", user.email, user.getDisplayValue());
Finally when I get the values of Users + Non-Users: I want them to be concatenated and added into the cc'ed field (copied) field of the notification.
Please let me know if you have any questions.
Regards,
Imran

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 06:00 AM
Understood, I think here you might want to iterate through list of emails that you have, if you find user, get the display value, if you don't just add them in the cc.
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(",");
for( var emailIndex in ccIds){
var user = new GlideRecord("sys_user");
user.addQuery("email", ccIds);
user.query();
if(user.next()) {
email.addAddress("cc", user.email, user.getDisplayValue());
}
else{
email.addAddress("cc", ccIds[emailIndex]);
}
}
}
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2022 07:18 AM
Hi Aman,
I ran your script in both background scripts as well as on actual email scripts by triggering the notifications still I get only the user from sys_user table and not the non-users.
I am thinking that the script is not passing on to ELSE part as the user record is found in IF part
In the background script I can see it iterates 3 times and all the three times I am seeing the same user from sys_user table
Not sure if we need to modify or do anything else to this script
Regards,
Imran