Inbound email actions to add users to watch list

Eric K3
Kilo Guru

I found the script below at http://wiki.servicenow.com/index.php?title=Useful_Inbound_Email_Scripts#gsc.tab=0http://

It adds the cc'd users to the watch list, but it also created another incident with the same incident number. Not sure what I am missing.

find_real_file.png

// 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

manikorada
ServiceNow Employee
ServiceNow Employee

Eric,



My apologies replace current.insert() with current.update()


View solution in original post

7 REPLIES 7

manikorada
ServiceNow Employee
ServiceNow Employee

Eric,



Try to remove the current.insert() at the last statement and check if it fixes the issue


removing current.insert(); resulted in the users not being added to the watch list.


manikorada
ServiceNow Employee
ServiceNow Employee

Eric,



My apologies replace current.insert() with current.update()


That change worked. Thank you.