Add Email to Watch List directly from Inbound Email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2011 01:37 PM
We've using our Service-Now instance for external customer support and need to be able to have non-users emails populate the Watch List field directly from an allowed inbound customer email.
Anyone have any experience with doing this without adding them as a user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2011 08:18 PM
You can put this inside your inbound action:
// Add All Email Recipients to Watch List
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;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2011 07:32 AM
Thanks I'll give that shot.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2011 12:32 AM
The only problem with this script is that it does not verify if the email recipients already exist on the watchlist.
Need help to improve on the script.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2011 04:56 PM
Haven't tested it, just wrote it here, but this should work:
// Add All Email Recipients to Watch List
var wList = current.watch_list;
var wListSplit = wList.split(',');
var wAdd = true;
var rarray = email.recipients_array;
var instanceEmail = gs.getProperty('glide.email.user');
for (var i = 0; i < rarray.length; i++) {
var recipient = rarray<i>;
for (var o = 0; o < wListSplit.length; o++) {
if(current.watch_list==wListSplit[o]){
wAdd = false;
}}
if(wAdd == true){
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;
}
}
}
}}