- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2022 12:05 PM
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, '', '');
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 11:43 AM
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(),"");
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 10:34 AM
Gunjan,
The user table query is taking a lot of time resulting in timeout, so i changing code to related list table query but this one is working , what am i missing ?
var userList = [];
var userRec = new GlideRecord("sn_si_m2m_task_affected_user");
userRec.addQuery('task',incidentNumber);
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(), "");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 10:41 AM
From where are you passing that Incident number in add query ?
userRec.addQuery('task',incidentNumber);
Is it variable which is storing incident sys_id or like that ? Because If you didn't declare that 'incidentNumber' then it will be undefined error.
Please check that and confirm.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 11:16 AM - edited 12-05-2022 11:18 AM
Incident number is the SIR number for secureity incident : I meant in previous comment not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 11:21 AM
In which table you are writing this code ?
If you wanted to pass the dynamic value then either use
userRec.addQuery('task',current.incidentNumber); //check proper back-end name of incident number from dictionary of field. I'm doubtful on the field name.
Use current If you are using a Business rule.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 11:29 AM
I want to pull email address of the users from m2m table sn_si_m2m_task_affected_user.
the notification is event triggered.