Remove Users from incident watch list.

Brian Lancaster
Tera Sage

I have a requirement that if a certain subcategory is selected I need to add two users to the watch list along with anybody already on it.  I have this working from a business rule.  I now need be able to remove these users if that subcategory is changed to anything else.  I'm not sure how to code the removal of the users from the watch list.  Any help would be appreciated.

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Here you go. Leverage OOB arrayUtil for this

 

var arrayUtil = new ArrayUtil();
var subCatArr = ["sys_id1", "sys_id2"];
var watchlistArr = current.watch_list.toString().split(',');
current.watch_list=arrayUtil.diff(watchlistArr,subCatArr).join();

View solution in original post

4 REPLIES 4

Shishir Srivast
Mega Sage

Are those the same two users, which are added, you want to remove? If yes, then i think you can have an array to save all the wtachlist users except those two users which you want to remove then set the value of array to watchlist.

Sample code, 

var nwl = [];
var wl = current.watch_list.toString();
var wla = wl.split(',');
for(var i = 0; i < wla.length; i++){
if(wla[i] != 'SYS_ID of the user you want to remove')
nwl.push(wla[i]);
}
current.watch_list = nwl.toString();

Abhinay Erra
Giga Sage

Here you go. Leverage OOB arrayUtil for this

 

var arrayUtil = new ArrayUtil();
var subCatArr = ["sys_id1", "sys_id2"];
var watchlistArr = current.watch_list.toString().split(',');
current.watch_list=arrayUtil.diff(watchlistArr,subCatArr).join();

Thanks that worked perfectly.