- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 09:31 PM
Hi everyone,
When sending notifications via email, in the 'Who will receive' section, I only want the notifications to be sent to email addresses ending with '@domain'.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 02:23 AM
I tried Business rule and it worked well
var myRecipients = current.recipients;
var accDomain = "@domain"; // Change the domain to send
if(myRecipients.contains(accDomain)){
var emailArray = myRecipients.split(',');
var accEmails = emailArray.filter(hasAccDomain);
current.recipients = accEmails.join(",");
current.update();
} else {
current.setAbortAction(true);
}
function hasAccDomain(email) {
return email.endsWith(accDomain);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 10:03 PM
Hello @12uy,
You can use an email script to group users whose email addresses end with @domain
in their email field. The following code snippet demonstrates how to achieve this:
(function() {
var recipients = [];
var userGR = new GlideRecord('sys_user');
userGR.addQuery('email', 'ENDSWITH', '@domain'); // Filter users with emails ending with '@domain'
userGR.query();
while (userGR.next()) {
recipients.push(userGR.email.toString());
}
// Set the recipients for the email notification
email.setTo(recipients.join(','));
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 01:34 AM
I tried to insert the code into the email script, but it didn't work. Could you guide me through the steps?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 10:07 PM
Hi @12uy You can easily achieve your requirement through Email Address filter. Read below docs mentioned and refer below screenshots.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0869547
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 02:23 AM
I tried Business rule and it worked well
var myRecipients = current.recipients;
var accDomain = "@domain"; // Change the domain to send
if(myRecipients.contains(accDomain)){
var emailArray = myRecipients.split(',');
var accEmails = emailArray.filter(hasAccDomain);
current.recipients = accEmails.join(",");
current.update();
} else {
current.setAbortAction(true);
}
function hasAccDomain(email) {
return email.endsWith(accDomain);
}