inbound email action with CC to watch list?

ABouland
Kilo Guru

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();

1 ACCEPTED SOLUTION

ABouland
Kilo Guru

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!


View solution in original post

7 REPLIES 7

ABouland
Kilo Guru

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!


Hi,

 

Any idea,,,,we want to add only CC of email to Incidents Watch List

 

Thanks in advance

Hi @ABouland,

I tried to do the same but still instance email is getting added in the watch list. 

 

Thanks,

Samiksha