Add Email to Watch List directly from Inbound Email

mwascak
Kilo Contributor

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?

7 REPLIES 7

gaidem
ServiceNow Employee
ServiceNow Employee

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;
}
}


}

}


mwascak
Kilo Contributor

Thanks I'll give that shot.


Not applicable

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.


gaidem
ServiceNow Employee
ServiceNow Employee

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;
}
}


}

}}