How to create system notification where notification should go to specific users?

Vishal_Jaiswal
Mega Guru

Requirement:
I need to configure a System Notification for the Incident table with the following logic:

  • If Assignment Group = Test Group and Assigned To = Abel Tutor

  • Then the notification should be sent to all members of "Test Group" except the assigned user (Abel Tutor).

What I Tried:

  • Created a notification record in sys_notification.

  • Defined the trigger conditions.

  • Added notification content in the Related List → Content → Next Experience (Subject + Body).

  • Tried defining receiver logic using an email script inside the Next Experience content.

Challenge:
The receiver logic is not working as expected — the notification is not being sent to the intended group members.

1 ACCEPTED SOLUTION

Hi @Ankur Bawiskar ,

Thanks again for your response and support.

Observation:

  • Case 1: In my official instance, when I add Assignment Group in the Who will receive tab, no bell notification goes to any user of the group. However, when I try the same in my PDI (Yokohama version), the bell notification goes to all users of the assignment group.

  • Case 2: In my official instance, when I add Assigned To in the Who will receive tab, the bell notification goes correctly to that user.

Conclusion:
It seems this may be either a platform/version issue (Official instance = Xanadu, PDI = Yokohama) or some configuration difference between the two environments.

Solution Implemented:
I changed my approach and found a working solution:

  1. Created a new Event.

  2. Added a Business Rule with logic to exclude the Assigned To user, and stored the sys_ids of all remaining users in the Assignment Group into a comma-separated array.

  3. Triggered the event in the Business Rule.

  4. Linked the event to a sys_notification record.

  5. Created a Next Experience content record for the notification body.

This approach worked successfully in my official instance.

View solution in original post

16 REPLIES 16

nityabans27
Giga Sage

Hi @Vishal_Jaiswal,

 

Step 1: Create the Notification

  • Table = Incident

  • Conditions = Assignment group = Test Group AND Assigned to = Abel Tutor

  • Make sure the notification event fires at the right time (on insert/update with conditions).


Step 2: Configure Recipients

Go to the Recipients tab in the Notification record.

  1. Don’t select the whole Test Group directly — otherwise the assigned user will also get the email.

  2. Instead, use a Scripted Recipient.


Step 3: Add a Scripted Recipient

  • In the Recipients tab → under "Script" → click New.

  • Add something like this:

(function(notification, current, template, email, event) {
    var recipients = [];

    // Get all group members
    var grMember = new GlideRecord('sys_user_grmember');
    grMember.addQuery('group.name', 'Test Group');  // or group.sys_id if you want it more stable
    grMember.query();

    while (grMember.next()) {
        var user = grMember.user;
        if (!user.nil() && user != current.assigned_to) {
            // Add recipient
            notification.addRecipient(user);
        }
    }
})(notification, current, template, email, event);

Step 4: Test

  • Assign an Incident to Abel Tutor in Test Group.

  • Run the notification → you should see all members of the group except Abel receiving it.

  • You can check System Logs → Emails to validate the recipient list.


Key takeaway:
Receiver logic must be in the Recipients (script) section of the Notification, not inside the content.

Hi @nityabans27 ,

Thanks for the response.

There is no Script field present in the Recipient tab.

Hi @Vishal_Jaiswal 

 

Since notifications don’t let you filter recipients via “Who will receive,” you can cancel delivery to the assigned user inside the Email Script, which controls who actually gets the email.

Email Script (Inside Notification Content)

Open the Email Script tab (under content for Next Experience) and insert this:

// Only send email to group members except the assigned user
(function filterRecipients(email, current, template, email_action, event) {

    var assignedUserID = current.assigned_to.sys_id;

    // Loop through the recipients already calculated
    var originalRecipients = email.recipients.toArray(); // returns array of GlideEmailRecipient
    for (var i = 0; i < originalRecipients.length; i++) {
        var recipient = originalRecipients[i];

        // Remove if it matches the assigned_to
        if (recipient.sys_id == assignedUserID) {
            email.removeAddress("to", recipient.address);
        }
    }

})(email, current, template, email_action, event);

 

Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."

Thanks @vignesh parthib ,

but this approcah is not working