Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Filter notification by role

chahinazekbz
Tera Contributor

Hi everyone,

 

I need some help with a notification issue.

I have a group of users with the “partner” role, and I want them to receive only three specific notifications — the ones whose names contain “Partner” (name in notification table )— and no others.

 

Since there are currently over 500 notifications on the platform, I can’t modify them manually.

 

I thought about creating a Business Rule on the sys_email table with a condition like:

 

if the user has the “Partner” role and the email subject doesn’t contain “Partner”, then abort the email.

 

However, the problem is that the three notifications don’t have any common keyword in their subject or name, so I can’t easily filter them that way.

 

thank you 

10 REPLIES 10

notification filter 3.pngnotification filter 2.pngnotification filter 1.png
I did that, but it’s not working.
Cenomi is a group of people with the partner role.
What could be missing?

notification filter 3.pngnotification filter 2.pngnotification filter 1.png

notification filter 3.pngnotification filter 2.pngnotification filter 1.png
I did that, but it’s not working. Cenomi is a group of people with the partner role. What could be missing?

Me Being Mustaq
Tera Guru

Hi @chahinazekbz ,

 

You're on the right track thinking about intercepting outbound emails via a Business Rule on the table — but since the subject line isn't a reliable filter, we’ll need a more robust and scalable approach. 

 

This approach is safer and easier to maintain, and it's specifically designed for your situation.

 

we need to Ensure users with the Partner role receive only the three intended notifications (whose notification record names contain “Partner”), and no others

 

We We'll use a Business Rule on sys_email that:

  1. Checks if the recipient has the partner role.

MeBeingMustaq_0-1762337251391.png

 2.Checks if the originating notification is not one of the three allowed ones.

3.Aborts the email if both conditions are true.

Step-by-Step Implementation

1. Tag the Allowed Notifications

Since the subject is unreliable, use a consistent identifier:

  • Add a custom field (e.g., u_partner_allowed – type: true/false) to the Notification [sysevent_email_action] table.

MeBeingMustaq_1-1762337495282.png

 

  • Set this field to true only for the three allowed notifications.

2. Create a Business Rule on sys_email

  • Table: sys_email
  • When: Before Insert
  • Condition: current.type == 'send'
  • Script:-
  • (function executeRule(current, gsr) {
    // Get the recipient
    var recipient = current.user_id;

    if (!recipient) return;

    // Check if the user has the 'partner' role
    var user = new GlideRecord('sys_user');
    if (!user.get(recipient) || !user.hasRole('partner')) return;

    // Get the notification that triggered this email
    var notif = new GlideRecord('sysevent_email_action');
    if (notif.get(current.notification)) {
    // If this notification is marked as allowed for partners, let it through
    if (notif.u_partner_allowed) return;
    }

    // Otherwise, abort the email
    current.setAbortAction(true);

    })(current, gsr);

 

My suggestions:-

  • Scalable:You only need to tag 3 notifications once.
  • Safe: Doesn’t rely on subject lines or brittle string matching.
  • Maintainable: Easy to update — just toggle the u_partner_allowed field.
  • Non-intrusive: Doesn’t require modifying 500+ notifications.
  • If you want to log or audit which emails are being blocked for partners, you can add a gs.info() or write to a custom log table before setAbortAction(true).

 

If it is helpful, please hit the thumbs button and accept the correct solution by referring to this solution in the future it will be helpful to them.

 

 

Thanks & Regards,

Mohammed Mustaq Shaik

 

You wrote current.notification, but the sys_email table doesn’t have a notification field.
Is there a way to retrieve it?