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

Hi,

Script looks fine. make sure your group field name is correct.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

For testing purpose, you can add hard-codded sys_id.

example -

 

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', 'c6c828c453751300ba3dddeeff7b1219'); // add your group sys_id
gr.query();
while (gr.next()) {
template.print("Users: " + gr.user.name.getDisplayValue());
}


Thanks,

Sagar Pagar

The world works with ServiceNow

I have tried for one group and its working but in same email its showing Hi name, name, name(user names) but if i give current .group its randomly taking non active user id with Hi text

Hi,

You have notification on Certification task table. How you are triggering the notification? I mean on which conditions you are sending the notifications.

 

If the event is fired from the Business rule, then while firing the events, you can pass the userid as 3rd parameter and getDisplayValue as 4th parameters.

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.group); // add your group sys_id
gr.query();
while (gr.next()) {
gs.evetQueue('event_name', gr, gr.getUserID(), gr.user.name.getDisplayValue());
}

 

In notification, You have to set send to event parameter 1 as true and in What will contain tab use this event.parameter as follows,

Hello dollar symbol {event (dot)parm2}, // dollar - symbol

//your notification body

 

If you are triggering the events from the workflow, you have to follow same process in create event activity.

 

Thanks,
Sagar Pagar

 

The world works with ServiceNow

Thanks for the response.

I have tried the same but no luck still getting only one ID. If possible could you please suggest how can we send this notification to all 4 members of group separately because currently its sending only 1 email with 4 recipients