How to send emails to all group members from sys_user_group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 09:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 10:30 AM
Yes I can give assignment group but there is email content in which i have to mention the name of the member and send to all members of that group this is the reason why i am writing mail script.
And second point assignment group is single select field only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 09:56 PM
okay. In that case just update your Notification Email script as below and this should work for you:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var getGroup = current.FIELDNAME; //Replace FIELDNAME with your Group Field Name
var arr = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',getGroup);
gr.query();
while(gr.next()){
arr.push(gr.getDisplayValue('user').toString());
}
for(var i = 0;i<arr.length;i++){
template.print('Hi ' + arr[i]);
template.print('Your other text here');
}
})(current, template, email, email_action, event);
This will print different Group member Name with Salutation as "Hi" and then in next line the content which you want to print you can add.
Let me know if you are stuck.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2022 01:44 AM
Did you got a chance to review the solution proposed by me above?
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2022 01:56 AM
Thanks for the response
I have tried it but with Hi i am not getting the member name but can we get 4 emails instead of 1 email because currently I am getting one email and in recipient its showing 4 names. If its triggers 4 emails that will be very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 11:01 PM
Hi,
Please try the below code.
var Arr=[];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('sys_id', 'current.group');
gr.query();
while (gr.next()) {
Arr.push(gr.user.email.toString());
}