- 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-03-2022 11:05 PM
Hi @Servicenow lear ,
You can pass multiple values separated by a comma. The email notifications just need a comma separated list of user sys_id's and you don't need to pass the name unless you want them to show up in the email to line. If you don't pass it, then just the email address will be present. Here is some example code to get a list of users and create an array that you can then pass to an event:
var userList = [];
var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery(YOUR-ENCODED-QUERY);
userRec.query();
while (userRec.next()) {
if (userList.toString().indexOf(userRec.sys_id) == -1) {
userList.push(userRec.sys_id + "");
}
}
gs.eventQueue("EVENT-NAME", 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 08:37 AM
hello Gunjan,
I did this but still no notification:
var userList = [];
var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery(email!=empty);
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 08:42 AM - edited 12-05-2022 08:43 AM
Enclosed encoded query in quotes.
var userList = [];
var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery("email!=empty");
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 09:32 AM
Thank you Gunjan, You have been really helpful.
Somehow the email query is becoming is so huge that it times out the transaction, not able to test it .
Let me fix the encoded query and get back to you