Send email notification to owner group

SNnewbie2
Tera Expert

I want to send an email notification to the owner group of a CI (cmdb_ci).

In my form, I have variable that is a reference to cmdb_ci. If the user selects 'WAM admin', I want to be able to send the email notification to the owner group of thaT ci.

find_real_file.png

I have an event in my workflow.

1 ACCEPTED SOLUTION

In line 05 there is mem.addQuery... why did you use 'group'.


It says "of all the records in this table, I only want the ones where the group field is the value of groupID (the same as the group in your support group field earlier.)



In line 08...I know you have to push the email members to the array but.. how do you know it will be mem.user.email.toString() ?   Like how do you know u have to use user   and email?


This is a concept known as dot-walking. It's a way to quickly traverse the relationships of reference fields and tables. I'm building an array of strings (email addresses.) By default, all fields are represented in memory as Javascript objects so I'm converting the email field to a string. That field is coming from the user record that is referenced by the mem record. mem.user is a sys_id to a record on sys_user. sys_user holds a user's profile details. I want the email address. That's what mem.user.email.toString() is doing.



In line 12... could you explain that line to me?


That's the line that actually tells the event engine to queue up the event "catalog.opening.dns.notification". The second parameter is the current record (which is the request item details, the third is your list of email address (converted from an array to a comma separated string), and the fourth is empty.



Events and Email Notifications - ServiceNow Wiki



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you


View solution in original post

25 REPLIES 25

Yes I do.


find_real_file.png



I used an script to create the event and to be sent out to support group.



var current = new GlideRecord('sc_req_item'); //queries the Requested Item table


current.get('baf7c8f013504300f7eb5e7f3244b099'); //The record you want to test against.


//Do not include the above in your final script


var groupID = current.variables.impacted_ci_first.support_group.toString();


gs.print('GroupID '+ groupID); //Did we get the groupID?


var userList = [];


var mem = new GlideRecord("sys_user_grmember");


mem.addQuery('group', groupID);      


mem.query();


gs.print('Users found '+mem.getRowCount()); //How many users have we found?


while (mem.next()) {


      userList.push(mem.user.email.toString());


}


gs.print("send event: catalog.opening.dns.notification to: " + userList.join(','));




I used the previous script to debug it. and I am getting the right group ID . But I checked my outbox and I can't see any notification.


Two other things to check... First, in the event log, is event parm 1 full of the email addresses (separated by commas) as you would expect?



Second, is this flag set on the notification under "Who will receive"?


find_real_file.png


There is nothing under parm1 and 2


find_real_file.png


Yes, it is


find_real_file.png


Hi Claudia,



I think I see the issue. Your event name is inconsistent. If your script is doing this:



var groupID = current.cmdb_ci.support_group.toString();


var userList = [];      


var mem = new GlideRecord("sys_user_grmember");      


mem.addQuery('group', groupID);  


mem.query();      


gs.log(mem.getRowCount());  


while (mem.next()) {      



              userList.push(mem.user.email.toString());      


}      



gs.eventQueue("catalog.opening.dns.notification", current, userList.join(','), '');



and your event registry entry has the same event name in it...



find_real_file.png



Then you will have an entry in the event log with the same name. Your's seems to have a " to:" on the end from your test script somehow.



The notification should also be set to trigger off the same event. That way everything is in sync.



When your script runs, it populates the array of email address and passed them to the event engine via the third parameter in the gs.eventQueue() call. That's known as "event parm1". You'll see that list in the log as well. When the email picks up the fact that the event has been fired, it uses event parm1 as the list of recipients. I did this in the Meetup app I built at Creator Con (see episodes CC17-1 and CC17-2) here if you want more clarification. The only difference is that I fired the events from a workflow, but the principle is the same.



TechNow Episode List


What do you mean by saying that my event is inconsistent? Where is the inconsistency?