- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 12:48 AM - edited 07-12-2023 12:49 AM
Hello All,
I'm using below script in inbound action to add the CC users in watchlist. It is working perfectly but it removes the users who are already in the watchlist.
try {
var notWatchers = ['test@service-now.com'];
var arr = email.recipients_array;
var watchList = current.watch_list;
var watchers = '';
for (var i = 0; i < arr.length; i++) {
if (notWatchers.indexOf(arr[i]) < 0) {
if (arr[i] != email.from) {
var gr = new GlideRecord('sys_user');
gr.get('email', arr[i]);
if (gr.next()) {
watchers = watchers + ',' + gr.sys_id;
} else {
watchers = watchers + ',' + arr[i];
}
}
}
}
current.watch_list = watchers;
} catch (e) {}
I wanted to append the CC users with the exisiting ones.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 12:55 AM
Updated script below: Basically you can read current watchlist as array and then go on adding new values in same array and then assign that array value to watch list field.
try {
var notWatchers = ['test@service-now.com'];
var arr = email.recipients_array;
var watchList = current.watch_list;
var watchers = current.watch_list.toString().split(",");
for (var i = 0; i < arr.length; i++) {
if (notWatchers.indexOf(arr[i]) < 0) {
if (arr[i] != email.from) {
var gr = new GlideRecord('sys_user');
gr.get('email', arr[i]);
if (gr.next()) {
watchers = watchers.push(gr.sys_id.toString());
} else {
watchers = watchers.push(arr[i] +"");
}
}
}
}
current.watch_list = watchers.join(",");
} catch (e) {}
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 12:55 AM
Updated script below: Basically you can read current watchlist as array and then go on adding new values in same array and then assign that array value to watch list field.
try {
var notWatchers = ['test@service-now.com'];
var arr = email.recipients_array;
var watchList = current.watch_list;
var watchers = current.watch_list.toString().split(",");
for (var i = 0; i < arr.length; i++) {
if (notWatchers.indexOf(arr[i]) < 0) {
if (arr[i] != email.from) {
var gr = new GlideRecord('sys_user');
gr.get('email', arr[i]);
if (gr.next()) {
watchers = watchers.push(gr.sys_id.toString());
} else {
watchers = watchers.push(arr[i] +"");
}
}
}
}
current.watch_list = watchers.join(",");
} catch (e) {}
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 01:33 AM
Hello @Ahmmed Ali It didn't work. Users are being removed from the watchlist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 01:46 AM
@Ahmmed Ali Actually it worked. I used my old code but I replaced the 4th line of yours which did the miracle. Thanks much.