
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2016 08:49 AM
I found the script below at http://wiki.servicenow.com/index.php?title=Useful_Inbound_Email_Scripts#gsc.tab=0http://
It adds the cc'd users to the watch list, but it also created another incident with the same incident number. Not sure what I am missing.
// Add All Email Recipients to Watch List
var wList = current.watch_list;
var gList = current.u_group_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];
//Check to see if this is a group address...and if so add to the group watch list
var grp = new GlideRecord('sys_user_group');
grp.addQuery('email', recipient);
grp.query();
if (grp.next()) {
if(gList != "") {
gList = (gList + "," + grp.sys_id);
} else {
gList = grp.sys_id;
}
} else {
//It's not a group address...so check to see if it's a user
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;
current.u_group_watch_list = gList;
current.insert();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2016 01:08 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2016 05:28 AM
I found another issue with this script. This script will add the user to the watch list, and a group to the group watch list, even when they are already listed. So the watch lists end up having two, three, four listings of the same user/group, basically every time an incoming email posts an update to the incident.
What method could I use to iterate through the recipients array to see if the recipient is already listed in the watch list or group watch list?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2016 09:58 AM
Hi Eric,
Could you please use below code for dedupe the user/group.
current.watch_list = dedupe(wList);
current.u_group_watch_list = dedupe(gList);
current.update();
function dedupe(p_value) {
var split_list = p_value.split(',');
split_list.sort();
var last = '';
for (var i = 0; i < split_list.length; i++) {
if (last == split_list[i]) {
split_list.splice(i, 1);
i--;
} else {
last = split_list[i];
}
}
return split_list.join(',');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2022 05:00 AM
Hi Senthil,
Could you please let me know if the above script needs to be added to existing script or replace it? Even i am facing the same issue as Eric. Please advice.
Regards,
Syed