How to get group users mail id dynamically

Tamil5
Tera Expert

Hi Friends,

I need to send a mail notification to some mail groups dynamically based on the condition.

I am not ready to create a mail id for my group.

But I need to get the mail ids of the group members.So that I can send them notification.

How to achieve this.Please advice

Thanks

Prici

1 ACCEPTED SOLUTION

Tamil5
Tera Expert

Thanks everyone for your time.


The following snippets did it..



var groupMemberMailIds = '';


var gr = new GlideRecord('sys_user_grmember');


gr.addQuery('group.name','<group-name>');


gr.query();



while(gr.next()){


  if(groupMemberMailIds != ''){


  groupMemberMailIds += ',' + gr.user.email;


  }else{


  groupMemberMailIds = gr.user.email;


  }


}


gs.log(' groupMemberMailIds are.....'+groupMemberMailIds);




Thanks


Chitra


View solution in original post

6 REPLIES 6

andrewdunn
Giga Expert

Hi Pricilla - not sure if this is what you are after but you can set up Email >> Notification and then select who will receive.



You would just need a field to identify who to send the email to



find_real_file.png


Hi Andrew,



I should have explained more..


I need to do this in Business Rule through script.


Before calling the event I will get the current Assignment Group name.



Based on the Assignment Group name I need to send notification to a group users.



Anyway I know we can give a mail id to group.



But what I need to do is,I need to get the group member list and based on their name I need to get the mail id.



Then I can send the notification to them.



Hope it is clear now.



Thanks


Pricilla


Pricilla,



You should be able to send to a group in a notification and ServiceNow should send to all members in the group assuming that there is no email address assigned for the group. So what if you trigger an event containing the group sys_id as parm 1 and the group name as parm 2 then have a notification send to parm 1 when the event is triggered?



Let me know if you have questions or that does not work.


andrewdunn
Giga Expert

Hi Pricilla - apologies,


Coding is not my specialty but are you able to dot walk along the following lines?


  • You have the assignment group (sys_user_group) - Name Field
  • Use this information against the group member table (sys_user_grmember) - Group Field
  • Utilise a While statement to get all members
    • For each member assigned to that group get the Email Field
    • Add this email to the list

Hope this gets you closer to a solution


cheers