- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2015 12:40 PM
I am working to integrate our helpdesk email into Service Now and recently found this article re: adding the email recipients to the INC watchlist: http://wiki.servicenow.com/index.php?title=Add_All_Email_Recipients_to_Watch_List#gsc.tab=0
I've modified from the article slightly to disregard groups/distribution lists for the moment. My question is how to further restrict this to only add internal employees that are CC'd to the watchlist, i.e. exclude anyone with e-mail address from a domain other than mydomainname.com - thoughts? Currently this will add anyone irregardless of whether the recipient address exists in our ServiceNow instance or not.
Current inbound action:
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.description = "Incident auto-generated via inbound e-mail sent to the helpdesk. \n" + email.body_text;
var sid = gs.createUser(email.from);
current.caller_id = sid;
current.opened_by = sid;
current.location = current.caller_id.location;
current.category = "Unprocessed";
current.assignment_group.setDisplayValue("Service Desk - All");
current.incident_state = 1;
current.notify = 2;
current.contact_type = "email";
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
if(email.importance != undefined)
if (email.importance == "High")
current.priority = 1;
if (email.body.priority != undefined)
current.priority = email.body.priority;
//add cc's to the watch list - commenting out secions dealing with group email and group watch lists
// Add All Email Recipients to Watch List
var wList = current.watch_list;
//var gList = current.u_group_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];
//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 = (gList + "," + grp.sys_id);
// } else {
// gList = grp.sys_id;
// }
// }
//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 = (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;
}
}
}
}
//}
current.watch_list = wList;
//current.u_group_watch_list = gList;
current.insert();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2015 06:46 AM
Looking at the script I am currently using a little more closely, I think I found my own answer - it's already looking at the addresses compared against my sys_user table to match anything up so if simply comment out the next section re:
} 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;
it seems to ignore anything that isn't already in my user table. I'll test it a little further but seems to be doing what I want.
Thanks for the suggestions!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2015 12:45 PM
Hi Andrew,
I'm going to move this thread to the bigger "Developer Community" area instead of the "Instance Help" area that it is currently in.
"Instance Help" is intended to help focus address operation issues with their Developer Program instances rather than implementation types of questions (which are more suitable for the "Developer Community" area).
Please let me know if you have any questions.
Thanks.
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2015 12:45 PM
Some sort of indexOf('@yourcompany.com') > 0 would give you people only of that domain.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2015 01:04 PM
Throw the email.copied field into an array. Loop through the array, add any email addresses that match your indexOf string into a new comma-separated string, then add that string into the watch list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2015 01:03 PM
Hi Andrew,
Something similar to the following at the start of the loop may work to limit processing (and addition) of recipients with an address that does not end in companyDomain to an incident watch list.
// Read the primary domain from a system property, or set directly
var companyDomain = gs.getProperty('com.yourcompany.primary_domain');
for (var i = 0; i < rarray.length; i++) {
var recipient = rarray[i];
// Does the current recipient have an address which does not end in companyDomain?
if (recipient.indexOf(companyDomain, recipient.length - companyDomain.length) < 0) {
// Yes, don't perform any further processing on this recipient
continue;
}
Hope that helps!