Sending Notifications Only to Newly Added Users in "Additional Assignee List" for Change Requests

ielmadani
Tera Expert

Hi everyone,

 

I need help configuring a notification in ServiceNow to notify only the newly added users in the Additional Assignee List for Change Requests. Here’s what I’m trying to achieve and what I’ve already tried:

 

Objective:

  • When: A Change Request is created or updated, and the Additional Assignee List is modified.
  • Who: Send notifications only to the newly added users in the Additional Assignee List.
  • Exclude: Previously added users should not receive the notification again.

 

What I’ve Tried:

1. Notification Configuration:

  • Set "Send When" to Record inserted or updated and checked both Insert and Update.
  • Set the Condition to Additional Assignee List changes.
  • Configured "Who will receive" as Additional Assignee List.

Problem: This sends notifications to all users in the field, including those already present.

 

2. Advanced Condition in Notification:

  • Used the following script to detect newly added users:

 

if (current.isUpdatedField('additional_assignee_list')) {
    var oldAssignees = previous.getValue('additional_assignee_list') || '';
    var newAssignees = current.getValue('additional_assignee_list') || '';
    var oldAssigneeArray = oldAssignees.split(',');
    var newAssigneeArray = newAssignees.split(',');

    for (var i = 0; i < newAssigneeArray.length; i++) {
        if (oldAssigneeArray.indexOf(newAssigneeArray[i]) === -1) {
            return true; // Trigger notification for new users
        }
    }
}
return false;

 

 

Problem: ServiceNow’s Advanced Condition field does not support return or complex logic, causing parse errors.

 

3. Business Rule with Events:

  • Created a Business Rule to compare current and previous values of the Additional Assignee List, identify newly added users, and fire an event:

 

if (current.isUpdatedField('additional_assignee_list')) {
    var oldAssignees = previous.getValue('additional_assignee_list') || '';
    var newAssignees = current.getValue('additional_assignee_list') || '';
    var oldAssigneeArray = oldAssignees.split(',');
    var newAssigneeArray = newAssignees.split(',');
    var addedUsers = [];

    for (var i = 0; i < newAssigneeArray.length; i++) {
        if (oldAssigneeArray.indexOf(newAssigneeArray[i]) === -1) {
            addedUsers.push(newAssigneeArray[i]);
        }
    }

    if (addedUsers.length > 0) {
        gs.eventQueue('notify.new_assignees', current, addedUsers.join(','), null);
    }
}
  • Created a Notification triggered by the notify.new_assignees event with Event Parm 1 contains recipient.

     

    Problem: While the event works correctly and Parm 1 contains the correct sys_ids of the new users, no notifications are sent.

4. Filter Condition on Notification:

  • Tried setting the Condition to Additional Assignee List changes, but this still sends the notification to all users in the field, not just the new ones.

 

How can I configure ServiceNow to send notifications only to newly added users in the Additional Assignee List, either using native features or a reliable script-based approach?

 

I’m doing my best to work through this, but as I’m not a developer, scripting is a bit outside my comfort zone. I’d appreciate any suggestions or examples that could help me get this working! 

 

Thank you in advance for your support!

 

1 ACCEPTED SOLUTION

@Ankur Bawiskar 

 

Found the issue. It was with the script.

 

The script you provided was checking for previous.watch_list and current.watch_list but these fields do not correspond to the additional_assignee_list that I wanted to monitor. So, I've replaced watch_list with additional_assignee_list.

 

I've also modified the third parameter (emailTo) in gs.eventQueue by adding a comma-separated string instead of passing it as an array. Here is the final script that I used and made it work:

 

 

(function executeRule(current, previous /*null when async*/) {
    var oldAssigneeList = [];
    var newAssigneeList = [];
    var emailTo = [];

    // Get the previous and current values of Additional Assignee List
    if (previous.additional_assignee_list)
        oldAssigneeList = previous.additional_assignee_list.split(',');

    if (current.additional_assignee_list)
        newAssigneeList = current.additional_assignee_list.split(',');

    // Find newly added users
    if (oldAssigneeList.length === 0) {
        emailTo = newAssigneeList; // All current assignees are new if the old list is empty
    } else {
        for (var i = 0; i < newAssigneeList.length; i++) {
            if (oldAssigneeList.indexOf(newAssigneeList[i]) < 0) {
                emailTo.push(newAssigneeList[i]); // Add only new assignees
            }
        }
    }

    // Trigger the event if there are new users
    if (emailTo.length > 0) {
        gs.log("Triggering event for new assignees: " + emailTo.join(','));
        gs.eventQueue('notify.new_assignees', current, emailTo.join(','), null);
    }
})(current, previous);

 

 

Thank you for your input and insight in helping me solving this issue! 

View solution in original post

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@ielmadani 

this approach won't work

Do these changes

1) in notification remove Who will receive" as Additional Assignee List.

2) then create an after update business rule on change_Request, condition as Additional Assignee changes

3) create event on change_request table

4) notification on change_request table and triggered when event is fired

a) Event parm1 contains recipient

Use this BR script

Updated with the correct field name

 

(function executeRule(current, previous /*null when async*/ ) {
    var oldwatch_list = [];
    var newwatch_list = [];
    var emailTo = [];

    if (previous.additional_assignee_list)
        oldwatch_list = previous.additional_assignee_list.split(',');

    if (current.additional_assignee_list)
        newwatch_list = current.additional_assignee_list.split(',');

    if (oldwatch_list.length == 0)
        emailTo = newwatch_list;
    else {
        for (var i = 0; i < newwatch_list.length; i++) {
            if (oldwatch_list.indexOf(newwatch_list[i]) < 0)
                emailTo.push(newwatch_list[i]);
        }
    }

    gs.eventQueue('notify.new_assignees', current, emailTo);
	
})(current, previous);

 

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

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

Hello @Ankur Bawiskar ,

 

Unfortunately, this doesn't resolve the issue. From the logs, I can confirm that the event was triggered successfully, but no notification was sent.

@ielmadani 

did you see recipients were set correctly?

Was the event processed?

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

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

@Ankur Bawiskar 

 

Yes, the event was processed and recipients are set correctly