Repeated name appear in watchlist selection field

SoumyasreeP
Tera Contributor

Hi ,

While I am working on configuration of watchlist in incident form, i found my name is repeatedly coming under watchlist field.

Record producer script 

var memberIds = (producer.watch_list + '').split(',');

var userIds = [];
for (var i = 0; i < memberIds.length; i++) {
var id = memberIds[i].trim();
if (!id) continue;
var gr = new GlideRecord('sys_user_grmember');
if (gr.get(id)) {
userIds.push(gr.user);
}

}
current.watch_list=userIds.join(',');
current.u_watch_list = userIds.join(',');
why its not working?
11 REPLIES 11

SoumyasreeP
Tera Contributor

Hi Malti,

there is no error coming,

Paul Kunze
Kilo Sage

Hi, you are querying the Group Member table so if your user has several memberships then it will return the user several times. You can use a GlideAggregate and group by user so that each one will only be returned once.

var gr = new GlideAggregate('sys_user_grmember');
gr.addQuery('sys_id', id);
gr.groupBy('user');
gr.setLimit( 1);
gr.query();
if(gr.next()){
   ...
}