How to send emails to all group members from sys_user_group

Priyanka77
Tera Guru

Hi,
There is one table in which there is a field "assignment group" which is referencing to "sys_user_group" and i need to send 4 same emails to group members mentioned in current group. Below is the email script written but still its coming empty in preview email. It should look like in email "Hi name(name of that group member)" for 4 users
var Arr=[];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('sys_id', 'current.group'); 
gr.query();
while (gr.next()) {
Arr.push(gr.user.name.getDisplayValue()); 
}

Can someone suggest some solutions.
Thanks in advance.
Priyanka

29 REPLIES 29

I want to send notification to group members with their name in content of email(Only one notification created). It should be like:
Hi member1(email 1)
Hi member2(email 2)
Hi member3(email3)
Hi member4(email 4)

Okay got it.

You want to send separate notification to all of the group members with name dynamically?

 

Thanks,
Murthy

yes exactly. Thanks

Create a BR and put your conditions 

Create event registry and call it from BR.

I have tried in my instance and it worked for me.

Sample code:

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("group", current.getValue("assignment_group"));
    gr.query();
    while (gr.next()) {
        gs.eventQueue("send_group_members", gr, gr.getValue("user"), gr.getDisplayValue("user"));
    }

})(current, previous);

Hi member1(email 1) - For this get the parm2 value and use it Message HTML something like below syntax:

Hi, Use dollar symbol here{event.parm2} //taking this value from parm2 in BR

It will trigger the notification to all group members separately.

 

Hope it helps.

 

Thanks

Murthy

Thanks,
Murthy

shloke04
Kilo Patron

Hi,

Couple of things here as listed below:

1. Why do you need a script first of all? What is the exact Use Case, can you share here? Reason being you can simply select the field on your notification form itself as shown below.

find_real_file.png

2. Secondly, even if you go ahead with a Script approach your Assignment group is a single select or multiple select value field? Can you confirm?

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke