How to remove specific user from WatchList
Import
·
Oct 06, 2021
·
article
This script will help you to remove specific element from a list of unique elements for eg sysIds.
Here I will take sys_id of the user a specific value and how can we remove it from a watch list present on an incident form.
We can write a Background script, Fix script or those use Xplore they can execute this script from there as well.
var sysId = '32 bit sysId'; //pass the 32 bit sys_id of the user you want to remove.
var inc = new GlideRecord('incident');
inc.get('number','INC0010112');// pass the correct number to get the record.
var arr = inc.watch_list.split(','); //split the watch list values and put them in an array.
var idx = arr.indexOf(sysId); //get the index of sys_id of user you want to remove from watch list.
arr.splice(idx,1); // Remove the specific user from array. idx is the index from which you want to remove and '1' is the number of elements you want to remove.
inc.watch_list = arr.join(','); // join the array and set the values back to watch list.
inc.setWorkflow(false); //if you don't want any BR to run for this update.
inc.update(); // update the record
If you like this piece of code the please Bookmark it, mark it Helpful and Subscribe it for further edition of methods.
Thanks,
Mohit Kaushik
View original source
https://www.servicenow.com/community/developer-articles/how-to-remove-specific-user-from-watchlist/ta-p/2314859