List of all users in the watchlist of all incidents

Gary22
Tera Contributor

Hi All 

 

I need to scan through the watch list of all incidents to see if a a user is present in watchlist of any open incident . As i will be doing this using a script include , is there a table containing the list of all users added to any incidents watchlist ? 

or will i have to glide through each incident record in a loop and scan through watchlist of each incident ? 

 

please guide

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Gary22 

You can create a function that takes the User Sys ID as a parameter and then executes a query using the watch_list condition.

For example, the code below returns an array containing the Sys IDs of the relevant incidents.

getIncidentsByWatchListUser: function(user_sys_id){
	var incidents = [];
	var grIncident = new GlideRecord('incident');
	grIncident.addActiveQuery();
	grIncident.addQuery('watch_list', 'LIKE', user_sys_id);
	grIncident.query();
	while(grIncident.next()){
		incidents.push(grIncident.getUniqueValue());
	}
	return incidents;
},

 

Cheers,

Tai Vu

View solution in original post

4 REPLIES 4

Sainath N
Mega Sage
Mega Sage

@Gary22 : As it's a field on the Incident table, you will need to loop through all the open incidents and check if the user is part of any watchlist.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

 

Habil Tabesh
Tera Contributor

Try This:

 

var gr = new GlideRecord('incident');
gr.query();

while (gr.next()) {
var watchList = gr.getDisplayValue('watch_list');
if (watchList) {
gs.info('Incident ' + gr.getValue('number') + ' has users in the watch list: ' + watchList);}
}

Habil Tabesh
Tera Contributor

This one will only look for open incidents: 

 

var gr = new GlideRecord('incident');
gr.addQuery('state', 'NOT IN', [7, 8]); // Filter for open incidents
gr.query();

while (gr.next()) {
  var watchList = gr.getDisplayValue('watch_list');
  if (watchList) {
    gs.info('Open incident ' + gr.getValue('number') + ' has users in the watch list: ' + watchList);

  }
}

Tai Vu
Kilo Patron
Kilo Patron

Hi @Gary22 

You can create a function that takes the User Sys ID as a parameter and then executes a query using the watch_list condition.

For example, the code below returns an array containing the Sys IDs of the relevant incidents.

getIncidentsByWatchListUser: function(user_sys_id){
	var incidents = [];
	var grIncident = new GlideRecord('incident');
	grIncident.addActiveQuery();
	grIncident.addQuery('watch_list', 'LIKE', user_sys_id);
	grIncident.query();
	while(grIncident.next()){
		incidents.push(grIncident.getUniqueValue());
	}
	return incidents;
},

 

Cheers,

Tai Vu