- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2024 04:30 AM - edited ‎08-13-2024 04:51 AM
Hi folks,
I had a requirement to add users to watchlist when priority is High/Critical I created br to get members from group and its working fine. But issue is when priority of same incident changes to low again the members are not removed from the watchlist. So they are still notified. Attaching br please help me how to remove users when priority is not high/critical @Ankur Bawiskar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2024 05:30 AM
Try this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2024 04:56 AM
you can use simple javascript logic and remove elements from array and then set values again
Remove multiple elements from array in Javascript/jQuery
How to remove multiple elements from array in JavaScript ?
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
‎08-13-2024 05:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2024 06:11 AM
I assume your BR is before update with condition as priority changes
try this
(function executeRule(current, previous /*null when async*/ ) {
var members = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.name', 'Incident Notification Alert - P1 Group Members');
gr.addQuery('user.active', true);
gr.query();
while (gr.next()) {
members.push(gr.getValue('user'));
}
if (current.priority == 1 || current.priority == 2) {
var new_memb = '';
if (current.watch_list.toString().length > 0)
new_memb = current.watch_list.toString() + ',' + members.join();
current.watch_list = new ArrayUtil().unique(new_memb.split(',')).join();
} else {
// logic to remove
var existingUsers = current.watch_list.toString().split(',');
var removalIndex = [];
for (var j = 0; j < existingUsers.length; j++) {
if (members.indexOf(existingUsers[j]) > -1)
removalIndex.push(j);
}
for (var i = removalIndex.length - 1; i >= 0; i--)
existingUsers.splice(removeValFromIndex[i], 1);
current.watch_list = existingUsers.join();
}
})(current, previous);
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
‎08-13-2024 07:55 AM
Hey @Ankur Bawiskar tysm for reply but sohail replied first the code and i implemented it was working