i want to update an existing watchlist to include a new user for all new incidents.

Wayne DeCoste
Tera Contributor

Hello.

We have a new user on the support team. How do I update an existing watchlist with this new user so he is notified when a new incident is created, or an existing incident is updated/closed? 

Is there a way to do this without running a script? 

 

Thanks!

1 ACCEPTED SOLUTION

That's great @Wayne DeCoste ,

 

Can you please mark the solution as accepted/helpful so that it helps future readers.

That will be much appreciated 🤗!

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

View solution in original post

19 REPLIES 19

Wayne DeCoste
Tera Contributor

FYI - I tried running my query through GPT and it suggested:

var gr = new GlideRecord('incident');
gr.addQuery('active', true); // filter as needed
gr.query();
while (gr.next()) {
// Append without overwriting
var currentWatch = gr.watch_list ? gr.watch_list.split(',') : [];
var newUser = '6816f79cc0a8016401c5a33be04be441'; // sys_id of user
if (currentWatch.indexOf(newUser) === -1) {
currentWatch.push(newUser);
gr.watch_list = currentWatch.join(',');
gr.update();
}
}

But, not being a java guy, Im not sure of this accomplished what I am trying to do ...

Wayne DeCoste
Tera Contributor

And, I dont want to overwrite the existing watchlist, just append.

 

@Wayne DeCoste ,

 

Use this script, It will update the watchlist if the user is not present in there.

var userToAdd = 'a8f98bb0eb32010045e1a5115206fe3a'; // sys_id of the user

var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.query();

while (gr.next()) {
    var currentWatchlist = gr.getValue('watch_list') || '';  
    var watchlistArray = currentWatchlist.split(',').filter(Boolean); 

    if (watchlistArray.indexOf(userToAdd) == -1) {  
        watchlistArray.push(userToAdd);
        gr.setValue('watch_list', watchlistArray.join(','));
        gr.update();
        gs.print(gr.number + " updated watchlist: " + gr.watch_list);
    } else {
        gs.print(gr.number + " already had the user in watchlist");
    }
}

 

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

Wayne DeCoste
Tera Contributor

Good morning! And thank you. 
So, this script will update any existing incidents, and add the user to any new incidents that are created? 

@Wayne DeCoste , Good morning!

It will update the existing incidents watchlist.

 

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain