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-10-2022 10:11 AM
Hi,
Can you verify that the values for those two entries are in fact...the same? The display may be the same, but if you run a background script check on that specific record, print the values for the watch list, what are you seeing?
Is it the exact same sys_id? or is it a sys_id + name or email...the ArrayUtil API (which you can read up on) and the unique method would remove literal duplicates.
So I'm thinking this looks like it's a duplicate, but in your system, it's not. Please verify.
The script I provided works as it's using the API and method to remove literal duplicates. I've tested it and supplied code as well.
As far as testing, please give me more information.
You keep testing with the same user. Please try one name on the watch list, different, than the CC.
The problem is the watch list would contain the user's sys_id, then the email.copied is an email address, so when it goes to look for matches, it doesn't see a match (one is a sys_id, one is an email) and then once the field gets set to it...the email entry resolves to a matching user. So that may be what's happening here, but if you add log statements to your inbound action, print the value of what the watch list is before the block of code runs, print after, then you'll see non-dupliactes.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!