Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

unable to send the trigger notification to assign to person

nikhilsoni5
Giga Contributor

I'm traying to create the business rule for notification requirement is we have activity record and which will be assigned to CBT member (CBT is as group) and as soon as some one update the comment on record should not receive the notification one the person who is assigned to the the record must receive the notification 

here is the script for the but its not working not sure what to do 

var cbtMemberEmails = [];
answer = getAnswer(cbtMemberEmails) || false;

function getAnswer(cbtMemberEmails) {
    var cbtMember = new GlideRecord('x_roho_rwd_activity_classification_confirmation');
    cbtMember.addQuery('portal_number', current.number);
    cbtMember.query();
    if (cbtMember.next()) {
        var cbtMemberRef = cbtMember.cbt_member.getRefRecord();
        var cbtMemberUser = cbtMemberRef.user.getRefRecord();
        var cbtMemberEmail = cbtMemberUser.email;
        var cbtMemberUserName = cbtMemberUser.user_name;
        var commenterUser = current.sys_updated_by;
        if (cbtMemberEmail && commenterUser != cbtMemberUserName) {
            cbtMemberEmails.push(cbtMemberEmail.toString());
gs.info('RWD_test_ntf:3 ' + cbtMemberEmails);
            return true;
        }


    }

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@nikhilsoni5 

why not use standard notification and send to Assigned to when Comments are updated?

You can check many OOTB incident related notifications for this.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

its notification script

Hi @nikhilsoni5 ,

Hi @nikhilsoni5 ,

For your notification script where you want to notify only the assigned CBT member on an activity record update when a comment changes—excluding the commenter themselves—here’s a complete example of a Notification Script (used in the "Who will receive" > "Advanced condition" or "Script" section of a notification):

// Notification Script to send to assigned CBT member except the commenter

// Array to hold the recipient emails
var cbtMemberEmails = [];

if (current.cbt_member) {
// Get the CBT member record reference (adjust field names as needed)
var assignedCbtMember = current.cbt_member.getRefRecord();
if (assignedCbtMember && assignedCbtMember.user) {
var user = assignedCbtMember.user.getRefRecord();
if (user && user.email) {
// Get current logged-in user sys_id (commenter)
var commenterSysId = gs.getUserID();

// If the commenter is not the assigned CBT member, add their email as recipient
if (user.sys_id.toString() !== commenterSysId) {
cbtMemberEmails.push(user.email.toString());
}
}
}
}

// Return recipients as a comma-separated string, or empty string if none
cbtMemberEmails.join(',');

 

You can use this script in this way 

  1. In your Notification record, go to the Who will receive tab.

  2. Choose Advanced condition > Script.

  3. Paste the above script.

  4. Ensure your Notification conditions only trigger on comment updates or relevant changes.

  5. This script returns the list of recipient email addresses as a string, restricting to the assigned CBT member excluding the current user.

Things we configured

  • Confirm current.cbt_member points to a record that has the .user field referencing a sys_user record with an email.

  • To limit the notification to only when a comment is updated, combine with conditions such as current.comments.changes() or a similar update check.

  • Testing in sub-production thoroughly will ensure it works as intended.

This notification script should ensure only the correct CBT member is emailed, not the commenter or others

 

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.

 

Thanks & Regards,

Mohammed Mustaq Shaik

Anupam1
Kilo Guru

Hi @nikhilsoni5 ,

 

Your script logic is close, but the issue likely stems from how you're triggering the Business Rule and how you're handling the notification recipient logic. To fix this, you should: (1) ensure the Business Rule runs on the correct condition, (2) return the email properly, and (3) use the result in a Notification or Email Script.

 

 

What You're Trying to Achieve

  • When a comment is added to an activity record:
    • Do NOT notify the commenter
    • Notify the assigned CBT member, if they are not the commenter

Step-by-Step Fix:

  1. Business Rule Setup
  • Table: x_roho_rwd_activity_classification_confirmation  (or wherever the comment is added).
  • When to run: After Update
  •  Condition: current.comments.changes() or current.comments.getJournalEntry(1) (depending on field name)
  • Advanced: Checked

 

2. Fix the Script Logic

  • Here’s a cleaned-up version of your script:

(function executeRule(current, previous) {

    var cbtMember = new GlideRecord('x_roho_rwd_activity_classification_confirmation');

    cbtMember.addQuery('portal_number', current.number);

    cbtMember.query();

 

    if (cbtMember.next()) {

        var assignedUser = cbtMember.cbt_member.user.getRefRecord();

        var assignedEmail = assignedUser.email;

        var assignedUsername = assignedUser.user_name;

        var commenterUsername = current.sys_updated_by;

 

        // Only notify if commenter is NOT the assigned user

        if (assignedEmail && commenterUsername !== assignedUsername) {

            gs.info('Notify CBT member: ' + assignedEmail);

 

            // You can trigger a notification here or set a flag

            current.cbt_notify_email = assignedEmail; // Custom field to pass to notification

        }

    }

})(current, previous);

 

3. Use in Notification

  • Create a Notification on the same table.
  • Condition: cbt_notify_email is not empty
  • Recipient: Use cbt_notify_email or script:

recipients.push(current.cbt_notify_email);

 

  • Email Body: Include relevant fields and comments.

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Thanks,

Anupam.

 

 

 

 

 

Could you please help me in understanding the below line, how exactly to configure this 

"// You can trigger a notification here or set a flag

            current.cbt_notify_email = assignedEmail; // Custom field to pass to notification"

Hi @nikhilsoni5 ,

 

This line is key to bridging your Business Rule and Notification setup. Let’s break it down and walk through how to configure it properly.

 

What the Line Does

current.cbt_notify_email = assignedEmail;

This line sets the value of a custom field called cbt_notify_email on the current record. It stores the email address of the assigned CBT member so that a Notification can later use this field to send an email.

 

How to Configure It Step-by-Step

  1. Create the Custom Field

You need to add a field to your table (x_roho_rwd_activity_classification_confirmation) to hold the email address.

  • Go to the table definition in ServiceNow Studio or Table Configuration.
  • Add a new field:
    • Name: cbt_notify_email
    • Type: String (or Email, if you want validation)
    • Label: CBT Notify Email
    • Default: Leave blank
    • Attributes: Optional, but you can make it read-only if you don’t want users editing it manually.

NOTE: If you want this field hidden from the form UI, set it to Internal or use a UI Policy to hide it.

 

2. Use It in the Business Rule

Your Business Rule already sets this field when the commenter is not the assigned CBT member:

if (assignedEmail && commenterUsername !== assignedUsername) {

    current.cbt_notify_email = assignedEmail;

}

This ensures the field only gets populated when a notification should be sent.

 

3. Configure the Notification

Now create a Notification that uses this field:

  • Table: x_roho_rwd_activity_classification_confirmation
  • When to send: Insert or Update
  • Condition: cbt_notify_email is not empty
  • Recipients:
    • Use a Script:
    • recipients.push(current.cbt_notify_email);
  • Email Body: Include relevant fields like comments, portal_number, etc.

 

Why This Approach Works

  • Keeps logic centralized in the Business Rule.
  • Avoids sending notifications to the commenter.
  • Allows flexible notification targeting without hardcoding user references.

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Thanks,

Anupam.