Duplicate users Watch List
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 09:08 AM
I added this to my inbound email actions to add users who are CC'd on an email to the watchlist of an incident/request:
current.watch_list = current.watch_list + ',' +email.copied;
This works great, only issue is it will infinitely add duplicates to the watch list as emails are exchanged and people are cc'd.
Any ideas?
Here's the full script for reference:
gs.include('validators');
if (current.getTableName() == "incident") {
current.watch_list = current.watch_list + ',' +email.copied;
var gr = current;
if (email.subject.toLowerCase().indexOf("please reopen") >= 0)
gr = new Incident().reopen(gr, email) || gr;
gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
if (gs.hasRole("itil")) {
if (email.body.assign != undefined)
gr.assigned_to = email.body.assign;
if (email.body.priority != undefined && isNumeric(email.body.priority))
gr.priority = email.body.priority;
}
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 11:52 AM
Hi,
So are you testing this on a pre-existing record with a watch list that was already there? If so, it appears that watch list had weird formatting since it just says ,name -- so that , in there can throw things off.
There may be times where this is no CC anyway, right? So we should account for that as well. Let's clean it up a bit more. Please ensure this record has a clean watch list, no users set on it, yet. Then you can re-save it with a few users as a test, then do the email with this adjustment:
if (email.copied) { //doing this check because if there's no CC, then no need to mess with watch list
var u = current.getValue('watch_list') + ',' + email.copied;
var array = u.split(',');
var arrayUtil = new ArrayUtil();
var finalArray = arrayUtil.unique(array);
}
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 02:09 PM
Gah, same result unfortunately, still duplicating.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 02:18 PM
Hi,
Can you please share a screenshot of the record activity log?
Did you do all the things above that I mentioned? Clear the watch list before hand, change the script slightly as posted above, re-test, etc.?
Actually I missed the line to update the watch list anyway...so this would be used:
if (email.copied) { //doing this check because if there's no CC, then no need to mess with watch list
var u = current.getValue('watch_list') + ',' + email.copied;
var array = u.split(',');
var arrayUtil = new ArrayUtil();
var finalArray = arrayUtil.unique(array);
current.watch_list = finalArray.toString();
}
Perhaps you saw that and added it? Else it shouldn't have duplicated as I didn't have that last line there.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 02:30 PM
Just to explain a bit more, this is a simulation of what should be happening. In background script you can test this yourself such as:
var string = 'email@example.com,email2@example.com' + ',' + 'email@example.com,newemail2@example.com';
var array = string.split(',');
var arrayUtil = new ArrayUtil();
var finalArray = arrayUtil.unique(array);
gs.info(finalArray.toString());
Which simulated two "email@example.com" entries, the ArrayUtil.unique() method seeing that and removing the duplicate.
This is the outcome:
So from the script I provided, we're getting the string value of the current watch list, and we're concatenating the email.copied (which should be a comma separated list of CC'd email addresses)...it should be doing the same thing.
So, you may want to add some log statements and see what you have doing on. Double check your email and the CC, double-check your test record or consider using a new one with no watch list, etc.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 09:51 AM
Still getting duplicates, heres my code now:
gs.include('validators');
if (current.getTableName() == "incident") {
if (email.copied) { //doing this check because if there's no CC, then no need to mess with watch list
var u = current.getValue('watch_list') + ',' + email.copied;
var array = u.split(',');
var arrayUtil = new ArrayUtil();
var finalArray = arrayUtil.unique(array);
current.watch_list = finalArray.toString();
}
var gr = current;
if (email.subject.toLowerCase().indexOf("please reopen") >= 0)
gr = new Incident().reopen(gr, email) || gr;
gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
if (gs.hasRole("itil")) {
if (email.body.assign != undefined)
gr.assigned_to = email.body.assign;
if (email.body.priority != undefined && isNumeric(email.body.priority))
gr.priority = email.body.priority;
}
gr.update();
}
I did what you mentioned. I actually created a new test ticket, no one on the ticket. Still seeing this result