I want to display the recipients in the body of email notifications sent to groups.

Minamizono
Tera Expert

I am currently creating email notifications like the following:


Who will receive: Users/Groups in fields “assignment group”
What it will contain: Message HTML (message body)

 

I want to display the names (name) of users belonging to the group in the message body. How can I do this?

1 件の受理された解決策

Minamizono
Tera Expert

I resolved this by sending the sysid of user and group as parameters during the event and using those values to create an email notification script.

元の投稿で解決策を見る

6件の返信6

Tanushree Maiti
Mega Sage

To display the names of users belonging to a specific group within a ServiceNow email notification body, you must use a Mail Script to query the group member table (sys_user_grmember) and print the names dynamically

 

1. Create an Email Script
  1. Navigate to System Notification > Email > Notification Email Scripts.
  2. Click New.
  3. Name: get_group_members
  4. Script:
    (function runMailScript(current, template, email, email_action, event) {
        // Assume 'assignment_group' is the field on the current record (e.g., Incident)
        
    
        if (groupId) {
            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('group', CURRENT.YOUR_GROUP_SYS_ID);
            gr.addQuery('user.active', true); // Only active users    
    gr.query(); template.print(
    "Group Members:\n"); while (gr.next()) { // Get the user's name template.print("- " + gr.user.getDisplayValue() + "\n"); } } })(current, template, email, email_action, event);
  5. Click Submit.
 
2. Add Script to Notification
  1. Open your Email Notification.
  2. In the Message HTML body, add the following line where you want the names to appear:
    ${mail_script:get_group_members}
  3. Save the notification
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Thank you for your comment.
However, what I want to do is not display all the names of members belonging to a group in a single email, but rather display the name of the recipient user in the body of the email sent to each individual user. The idea is something like “Dear ${user.name}”.

Hi @Minamizono 

Can you try with

 Dear ${assignment_group.member}

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@Minamizono 

not possible to include member's name when email goes to group

use after insert/update BR and fire event per group member, then it's possible

Populate Assignment Group members first name in Email body of notifications  -> approach from Kieran

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader