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

That's what I need you to check.



Is the name used in the script the same as in the registry and the same as in the notification? The one you had in the latest script had that suffix " to:" which meant nothing is going to respond to it.


I don't think that is the issue. My group didn't have any members and that's why It was returning 0 for the member #.


Now I am able to see the members and the emails but THERE IS NO NOTIFICATION SENT TO THOSE ADDRESSES.


find_real_file.png


I checked my outbox and there is nothing...


Okay It worked!!!



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


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


var userList = [];


var mem = new GlideRecord("sys_user_grmember");


mem.addQuery('group', groupID);      


mem.query();


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


while (mem.next()) {


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


}


//gs.eventQueue('catalog.opening.dns.notification' + userList.join(','));


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




I have a couple of questions for you.


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


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?


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



Line 08:


I dont see anything that says user or email here(picture):


find_real_file.png


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


Thank you Chuck Tomasi! The reason that I asked is because I am doing another script but for the manager and I need to understand each line.


I have a last question for you. Before I did an script to send the notification to the support_group. This time I want to send it to the owned_by which is a manager. So I wrote my script similar to the one before and it it returning the right manager ID, but it doesn't get any member(himself) or email.



//Create an Event and send it to Solutions Manager.


var solManagID = current.variables.impacted_ci_first.owned_by.toString();


gs.print('sol ID '+ solManagID ); //Did we get the groupID?  




var solutionsManager =[];


var mem = new GlideRecord("sys_user_grmember");


mem.addQuery('group', solManagID);


mem.query();


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




while (mem.next()){


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


}


gs.print("catalog.opening.dns.notification", current, solutionsManager.join(','), '');



Any idea why?