Code for adding multiple user emails in the event queue

Servicenow lear
Tera Contributor

Hello All,

 

We have an Event which triggers a notification on Security Incident response.

I am looking for code of adding Users email address to event so that the notification can be sent to email address of users in Affected user related list.

Table : sn_si_m2m_task_affected_user

Event : gs.eventQueue('sn_si.secops.trigger.spam.email', current, '', ''); 

1 ACCEPTED SOLUTION

Okay then writedown code as below. But make sure you have push the correct email address by writing proper field name for email in below script.

 

 

var userList = [];
var userRec = new GlideRecord("sn_si_m2m_task_affected_user");
userRec.addQuery('task',current.sys_id);
userRec.query();
while (userRec.next()) {
if (userList.toString().indexOf(userRec.sys_id) == -1) {
userList.push(userRec.sys_id + "");
}
}


gs.eventQueue('sn_si.trigger.spam.email', current, userList.toString(),"");

View solution in original post

13 REPLIES 13

But where did you written that above script?

In email Script or in BR or somewhere else ?

Ui action,  event is associated with a UI action on Security Incident table.

trigger UI action >>Event >>notification to users in related list. 

 

Okay then writedown code as below. But make sure you have push the correct email address by writing proper field name for email in below script.

 

 

var userList = [];
var userRec = new GlideRecord("sn_si_m2m_task_affected_user");
userRec.addQuery('task',current.sys_id);
userRec.query();
while (userRec.next()) {
if (userList.toString().indexOf(userRec.sys_id) == -1) {
userList.push(userRec.sys_id + "");
}
}


gs.eventQueue('sn_si.trigger.spam.email', current, userList.toString(),"");

thanks Gunjan the code worked .. You have been really helpful. cheers ! 

this is the code that worked :

var userList = [];
var userRec = new GlideRecord("sn_si_m2m_task_affected_user");
userRec.addQuery('task',current.sys_id);
userRec.query();
while (userRec.next()) {
if (userList.toString().indexOf(userRec.sys_id) == -1) {
userList.push(userRec.user.email + "");
}
}