How to add users from CC to watchlist?

Dawid2
Giga Guru

Hello,

I am looking to implement functionality that will add CC'd users from email to watchlist automatically. I've found couple of topics here and used following code. While it works fine, it also adds users from "To" field of the email (so in my case our instance email address). Is it possible to limit this so only CC'd users are added and not users from "To" field?

//populate watchlist from cc filed

var wList = current.watch_list;
var rarray = email.recipients_array;
var instanceEmail = gs.getProperty('glide.email.user');

for (var i = 0; i < rarray.length; i++) {
var recipient = rarray[i];
var gr = new GlideRecord('sys_user');
gr.addQuery('email', recipient);
gr.query();
if (gr.next()) {
// It's a user
if(wList != "") {
wList = (wList + "," + gr.sys_id);
} else {
wList = gr.sys_id;
}
} else {
//It's not a user either...so just add the address to the list...except instance email address
if (recipient != instanceEmail) {
if(wList != "") {
wList = (wList + "," + recipient);
} else {
wList = recipient;
}
}
}

}
//}

current.watch_list = wList;
1 ACCEPTED SOLUTION

VigneshMC
Mega Sage

What happens when you just try

current.watch_list +=email.copied;

or

current.watch_list = current.watch_list  + ',' +email.copied;

Thanks

View solution in original post

11 REPLIES 11

Cody17
Tera Contributor

Is there a way to also add users from the TO line of an email, as well as the CC'd users?

devendra9
Tera Contributor

using this code I am able to add 'TO' person and 'CC' person into the watchlist, but the problem is same person added twice in the watchlist and the personal Email ID when we replied back using the same email, and we don't want to add the same person twice and the personal Email ID. can anyone help on this, how can we restrict to add same person twice.