- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 02:54 AM
Hi,
I have an Email Notification which is sent to the Group XYZ. How can I get the User's Name of each member in the group XYZ so that I can start the notification with a personalized greeting for each.
Is there, for example, a field that I can use in the notification body or do I have to write a script? If yes, which variable can I use to get the email's recipients in the mail script.
Thanks in advanced!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 09:24 AM
Hi
This behavior is by design!
ServiceNow Notifications work to fire ONE Email per Notification that is fired (with one exception, that ServiceNow will create automatically several SIMILAR Emails if the number of recipients for ONE Mail exceeds 100).
Result A:
ONE Email sent to (e.g.) 55 Recipients (in the "TO", "CC" or "BCC" field). This creates ONE Email object in your Outbox/Sent mailboxes
In that case, you cannot send the SAME Email with an individual and personalized greeting like you are trying to do.
In that case, you also need to create an individual email per each recipient.
Result B:
Having 55 Recipients, you will end up in having 55 individual email records in your outbox/sent mailbox in ServiceNow, each having only ONE Recipient in either the "TO", "CC" or "BCC" field.
What you are heading for, is "Result B", which you could achieve by using the Mail API (and maybe a script holding a look to fire the desired number of Notifications - e.g. by firing Events, etc.)
So, you cannot create ONE Email holding personalized greetings based on one Notification, but you can create any number of different personalized emails based on one Notification - using scripting.
Let me know if that answers your question and mark my answer as correct/helpful.
Thanks & BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 03:14 AM
Hi Pake,
you can use the Email Notification script as below and then you can call this script in the notification.
so that can print all the users of that group.
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', CURRENT.YOUR_GROUP_SYS_ID);
gr.query();
while(gr.next())
{
gs.print(' User is ' + gr.user.getDisplayValue());
}
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 03:21 AM
Thank you for your answer. Maybe my explanation was bad but I don't want to list all users.
If the group has the users John, Alex and Marc, I want that the mail to John starts with "Dear John" and the mail to Alex starts with "Dear Alex".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 03:29 AM
Hi,
I believe even if you use email.setSubject() from your mail script; all recipients will get same subject
I believe the only way here would be to have separate email triggered for every recipient and in the email script determine the recipient and set the subject accordingly
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 03:35 AM
What a pity! I don't understand why there isn't a field like ${recipient.user_name} or something like that 😄
Nevertheless thank you Ankur!