How to push multiple users to watchlist

Roshini
Giga Guru

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;

              }

1 REPLY 1

Sai Kumar B
Mega Sage
Mega Sage

@Roshini 

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