Adding Users (Sys) to Watchlist on Inbound Action

Paul_Allen
Kilo Contributor

Hi

I am using Kingston and have tried a number of different scripts but none seem to work.

For NEW Email in (HR) I need an action that puts all of the CC people into the Watchlist Automatically, the only one so far that seems to work only adds their email address instead of their sys id which doesn't solve my issue

Essentially, if their email address exists then sys id, otherwise their email address.

Any takers?

1 ACCEPTED SOLUTION

Can you try this script

 

// Add All Email Recipients to Watch List
var wList = current.watch_list;
var gList = current.u_group_watch_list;
var rarray = email.recipients.toLowerCase().split(",");
var instanceEmail = gs.getProperty('glide.email.user');

for (var i = 0; i < rarray.length; i++) {
var recipient = rarray[i].toString();

//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 += "," + grp.getValue('sys_id');
} else {
gList = grp.getValue('sys_id'); //getting reset before
}
} 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 += "," + gr.getValue('sys_id');
} else {
wList = gr.getValue('sys_id');// getting reset before
}

} 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; //getting reset before
}
}
}
}
}
current.watch_list = wList;
current.u_group_watch_list = gList;
current.update();


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

8 REPLIES 8

Paul_Allen
Kilo Contributor

Hi, still nothing unfortunately, the watch list just comes back blank all the time 

Can you try this script

 

// Add All Email Recipients to Watch List
var wList = current.watch_list;
var gList = current.u_group_watch_list;
var rarray = email.recipients.toLowerCase().split(",");
var instanceEmail = gs.getProperty('glide.email.user');

for (var i = 0; i < rarray.length; i++) {
var recipient = rarray[i].toString();

//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 += "," + grp.getValue('sys_id');
} else {
gList = grp.getValue('sys_id'); //getting reset before
}
} 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 += "," + gr.getValue('sys_id');
} else {
wList = gr.getValue('sys_id');// getting reset before
}

} 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; //getting reset before
}
}
}
}
}
current.watch_list = wList;
current.u_group_watch_list = gList;
current.update();


Please mark this response as correct or helpful if it assisted you with your question.

Yeey! - This one worked, I had to tweak slightly and replace 'recipient' with 'copied' but working perfectly now!

Rob Sestito
Mega Sage

Hey Paul,

I wanted to do something similar, but not to the watch list - I have a custom field where I wanted the inbound action to send all CC'd users to (as long as they match a user account within the system).

Check out my post How to add CC'ed users from inbound email to a custom field?

It took some time, but I was able to get help from people there - I marked an answer as correct (which it was for the most part) - but also added my entire inbound action code that worked perfectly for me.

But, if any of those CC'd users replied to the original email, it may create a new Case. So I received help on adding code to the Update Case inbound action as well - Help with Inbound action - HR Case Update

Hope this helps you out!

-Rob