Remove member from watchlist

Priyanka Chaud1
Tera Contributor

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 

(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'));



  }


  var new_memb='';


  if(current.watch_list.toString().length>0)


  new_memb=current.watch_list.toString()+','+members.join();


  else


  new_memb=members.join();


  current.watch_list=new ArrayUtil().unique(new_memb.split(',')).join();
 

 


})(current, previous);



1 ACCEPTED SOLUTION

sohail_mohamad
Tera Expert

Try this

 

(function executeRule(current, previous /*null when async*/) {
    var members = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group.name', 'database'); // give your group here
    gr.addQuery('user.active', true);
    gr.query();

    while (gr.next()) {
        members.push(gr.getValue('user'));
    }

    var currentWatchList = current.watch_list ? current.watch_list.split(',') : [];
    var newWatchList = [];

    if (current.priority < 3) { // Priority 1 or 2
        newWatchList = currentWatchList.slice();
        var membersToAdd = members.filter(function(member) {
            return newWatchList.indexOf(member) === -1;
        });

        newWatchList = newWatchList.concat(membersToAdd);
    } else {
        newWatchList = currentWatchList.filter(function(userId) {
            return members.indexOf(userId) === -1;
        });
    }

    current.watch_list = new ArrayUtil().unique(newWatchList).join(',');

})(current, previous);
 
 

View solution in original post

13 REPLIES 13

sohail_mohamad
Tera Expert

Try this

 

(function executeRule(current, previous /*null when async*/) {
    var members = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group.name', 'database'); // give your group here
    gr.addQuery('user.active', true);
    gr.query();

    while (gr.next()) {
        members.push(gr.getValue('user'));
    }

    var currentWatchList = current.watch_list ? current.watch_list.split(',') : [];
    var newWatchList = [];

    if (current.priority < 3) { // Priority 1 or 2
        newWatchList = currentWatchList.slice();
        var membersToAdd = members.filter(function(member) {
            return newWatchList.indexOf(member) === -1;
        });

        newWatchList = newWatchList.concat(membersToAdd);
    } else {
        newWatchList = currentWatchList.filter(function(userId) {
            return members.indexOf(userId) === -1;
        });
    }

    current.watch_list = new ArrayUtil().unique(newWatchList).join(',');

})(current, previous);
 
 

Hey @sohail_mohamad i tried ur code its not working for remove user for adding its working

@Ankur Bawiskar can you please help me

Before - Update & Insert

Priority - Changes