Notify remaining 'Watch list' users when comments added by one of the users in 'Watch list' field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 11:30 AM - edited 01-17-2025 12:02 PM
Hello,
We have a requirement to send email notification to remaining users in 'Watch list' field when comments are added by one of the user in the same 'watch list' field.
The tricky part of the requirement is to exclude the commented user from recipients list. When 'watch list' field is added to 'who will receive' in the notification setting, system is notifying all the users in 'Watch list' including the commented user.
Example:
If watch list field contains 4 users as A, B, C, D.
When A comments, requirement is to notify only B, C, D excluding A.
Not sure if we can achieve this without scripting?
If not, help with script is appreciated.
Help please.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2025 11:57 PM
Hi @RGC9 ,
You can do this by scripting. Run a business rule, whenever an Incident Additional comments are updated.
Filter the Watchlist from the current user, and sent the users in the Parameter using a event for the notification.
Business rule:
var watchList = current.getValue('watch_list');
var watchListArray = watchList.split(',');
var index = watchListArray.indexOf(gs.getUserID());
if (index !== -1) {
watchListArray.splice(index, 1);
}
var updatedWatchList = watchListArray.join(',');
gs.eventQueue('event.name',current,current.number,updatedWatchList)
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2025 06:54 AM
you cannot do it via Who will receive as all watch list users will receive it
you will have to do it via Event, BR approach and remove that user from the notification recipient list
OR
you can also use Flow designer with no scripting
BR Approach
1) After update BR on incident table. condition Comments Changes
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var currentUsersArr = current.watch_list.toString().split(',');
var commentAddedByUser = gs.getUserID();
var index = currentUsersArr.indexOf(commentAddedByUser);
if (index > -1) {
// only splice array when item is found
currentUsersArr.splice(index, 1); // 2nd parameter means remove one item only
}
gs.eventQueue('eventName', current, currentUsersArr.toString());
})(current, previous);
2) have event on incident table
3) have notification on incident table and link above event
a) Event parm1 contains Recipient - true
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2025 07:16 AM
Hi Ankur,
Any chance you could guide me how to achieve the same in flow?
Thank you very much for your time and effort on this!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2025 07:20 AM
Thank you for marking my response as helpful.
I believe I provided solution to your question with 1 approach.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader