The CreatorCon Call for Content is officially open! Get started here.

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

Vishal_Jaiswal
Tera Contributor

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.

15 REPLIES 15

nityabans27
Giga Guru

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