- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 07:27 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 07:54 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 07:33 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 07:45 PM
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);}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 07:51 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 07:54 PM
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