Script to add cc'd users to watch list

mkader
Kilo Guru

Hello,

I need to create an inbound action that auto populates the watch list with  cc'd user(s) for RITMs. How can I do this? If a cc'd user does not exist in the system, I do not want to create a new user

Thanks!

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Within this inbound action, in the script section, you can retrieve the "copied" users (aka CC'd) which will give you a comma separated string of their email address. From there, you can query your sys_user table to find a match based off of this and if found, add them to your watch list.

Something like:

var copied = email.copied;
var watchList = current.watch_list;
var findMem = new GlideRecord('sys_user');
findMem.addQuery('email', 'IN', copied);
findMem.addQuery('sys_id', 'NOT IN', watchList);
findMem.query();
while (findMem.next()) {
current.watch_list += "," + findMem.sys_id;
}
current.update();

I just tested this myself and it does work. So as long as your inbound action has found the correct record to associate the email to, this will work just fine.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

23 REPLIES 23

Well when an email is brought in, most inbound actions are set to "stop processing", so that means it'll only "run" the one inbound action. Depending on what you're trying to do, you may need to relate it to one already built and in use.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi, seems you got it all resolved.

I believe my code above would work as well as I had tested it out. This would review who is currently in your watch list, and not add them again, but only add new users who are registered in your system. A bit less code, but either way, there's many ways to get to the answer 🙂

Take care!

Please mark any other reply as Helpful, through this thread, if it was.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

@Allen A - Sorry wish we could mark multiple answers as correct. I went ahead and used yours because it is shorter. It works fine in my PDI, but is not working in my DEV instance. Any ideas on why that is? I've followed the same steps and brought over the same inbound action. I tried adding a log, but am not seeing anything display in the logs. I've also created a dummy user and dummy email as I did in my PDI and nothing

Figured out the issue. Had to enable inbound emails in mail properties

Hi Allen,

 

I tired this script in my inbound email action but its not working ,

 

could you please help me on this 

 

var copied = email.copied;
var watchList = current.watch_list;
var findMem = new GlideRecord('sys_user');
findMem.addQuery('email', 'IN', copied);
findMem.addQuery('sys_id', 'NOT IN', watchList);
findMem.query();
while (findMem.next()) {
current.watch_list += "," + findMem.sys_id;
}
current.update();

 

thanks

sid