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

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

Me Being Mustaq
Tera Guru

Hi @nikhilsoni5 ,

 

Your script aims to:

  • Find CBT group members related to the activity record via a linked record 

  • Get their email.

  • Check if the commenter (current.sys_updated_by) is different from that CBT member.

  • If so, add their email to a notification recipient list to notify only the person assigned.

However, the provided script is incomplete and has a few issues:

  • The function does not return any false or default value explicitly if conditions aren't met.

  • The logic assumes only one CBT member per record; multiple members aren't handled.

  • The script captures the sys_updated_by as a string username but compares improperly.

  • The usage context (Business Rule, Notification Script, or Script Include) isn't clear.

This corrected version should help gather the right CBT member emails excluding the commenter on update and form the basis for sending targeted notifications.

 

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

Can you please help me with the modified script

Hi @nikhilsoni5 ,

 

If this is a Business Rule or Notification Script on the activity record update:

 

(function executeRule(current, previous /*null if insert*/) {
var cbtMemberEmails = [];

// Query related CBT member record for the current record
var grCBT = new GlideRecord('x_roho_rwd_activity_classification_confirmation');
grCBT.addQuery('portal_number', current.number);
grCBT.query();
while (grCBT.next()) {
var cbtMemberUser = grCBT.cbt_member.user.getRefRecord();

// Skip if no user or email
if (!cbtMemberUser || !cbtMemberUser.email)
continue;

// Compare commenter username to CBT member user name (sys_updated_by is user sys_id string or username?)
// It's safer to compare sys_id of commenter to sys_id of CBT member
var commenterId = gs.getUserID();
if (commenterId != cbtMemberUser.sys_id.toString()) {
cbtMemberEmails.push(cbtMemberUser.email.toString());
}
}

gs.info('RWD_test_ntf: CBT member emails to notify - ' + cbtMemberEmails.join(', '));

// Now, cbtMemberEmails contains emails of CBT members to notify excluding the commenter

// Your notification logic to use cbtMemberEmails here, e.g. add to email notification recipients or flag

})(current, previous);

 

Important Considerations:

  • Make sure cbt_member field really points to a reference record that has a .user reference field as you used.

  • Use gs.getUserID() to get the current user sys_id instead of current.sys_updated_by string for accurate comparison.

  • If you want to prevent notification to other users and send only to these CBT members, you may need to customize notification or email recipient logic accordingly.

  • If this is part of a notification condition or script, you may only return true/false or set additional fields to control recipients.

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