How to push multiple users to watchlist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 11:12 PM
I am having a field called ‘business unit’ in “sys_user” table and ‘business unit’ in incident table.
Whenever the business unit is a particular value(“SN NW”) in incident table all the users who are having the same business unit should be added to watchlist. So I have wrote a BR, where it is updating one user into the watchlist, can I know what modifications I have to do in order to get all the users name into watchlist.
var BU = current.business_unit.getDisplayValue();
var user = new GlideRecord(‘sys_user’);
user.addQuery(‘business_unit' ,BU);
user.query();
while (user.next()) {
current.watch_list = user.name;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 01:39 AM
Try the below
var arr=[];
var user = new GlideRecord(‘sys_user’);
user.addQuery(‘business_unit' ,current.getValue(business_unit));
user.query();
while (user.next()) {
arr.push(user.getValue('sys_id')); //Push user sys_ids into an array
}
current.setValue('watch_list' ,arr); //Set array of values into watch list