- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2024 03:31 AM
Goal
The goal is to add a field style (represented by a green teal dot) to the incident list view when either the caller or a user listed in the Additional Information or Work Notes watch list responds or updates the incident. While the field style works correctly for the caller, it fails to apply when users on the watch lists make updates.
Issue
The issue lies in the field style condition. While it successfully looks up the last updated entry in the sys_audit table and returns the user, the lookup on the watch_list (a Glide List) fails, resulting in the condition not being met.
Examples (Working for Caller, Not for Watch Lists)
Example 1:
- Condition: (current.caller_id.user_name == current.sys_updated_by) || (current.watch_list.includes(current.sys_updated_by))
- Description: This condition checks if the last updated user matches the caller or if the user is in the watch list.
- Works for the caller but not for watch lists.
Example 2:
- Condition: (current.caller_id.user_name == current.sys_updated_by) || (current.sys_updated_by IN current.watch_list)
- Description: Similar to Example 1, this condition aims to achieve the same result.
- Also works for the caller but not for watch lists.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2024 10:23 PM
We created a new Field Style (sys_ui_style)
Incident - table
Number - field
Value to look up Watch_list ONLY:
Condition= "javascript: new global.OMGIncidentUtils().watchlistUpdatedIncident(current.sys_id) ==true;"
//-----Script include
// Client Callable, All Application Scopes
//API Name - global.OMGIncidentUtils
//Name - OMGIncidentUtils
var OMGIncidentUtils = Class.create();
OMGIncidentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
watchlistUpdatedIncident: function(sysID) {
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', sysID);
incidentGR.query();
if (incidentGR.next()) {
//Watchlist comma seperated into an array
var watchlistArr = incidentGR.watch_list.split(',');
var watchListUserIds = watchlistCheck(watchlistArr);
var userInWatchlist = validationWatchlist(incidentGR.sys_id, watchListUserIds);
return userInWatchlist;
}
function watchlistCheck(arrayList) {
var watchlistDotArr = [];
for (i = 0; i < arrayList.length; i++) {
var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id', watchlistArr[i]);
userGr.query();
if (userGr.next()) {
watchlistDotArr.push(userGr.user_name);
}
// gs.info('The user ids for the watchlist members: ' + watchListDotArr);
}
return watchlistDotArr;
}
function validationWatchlist(recordId, listArr) {
var inGr = new GlideRecord('incident');
inGr.addEncodedQuery('sys_idSTARTSWITH' + recordId + '^sys_updated_byIN' + listArr);
inGr.query();
if (inGr.next()) {
return true;
} else {
return false;
}
}
},
type: 'OMGIncidentUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2024 04:05 AM
Please use the below conditions and check.
Example 1:
Condition:
Example 2:
- Condition:(current.caller_id.user_name == current.sys_updated_by) || (current.sys_updated_by.indexOf(current.watch_list) > -1)
Thanks & Regards,
Anitha H V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2024 10:17 PM
Hi Anitha,
Thanks for your input but this didn't resolve the issue, because the updated_by is the userID, while the Watch List is sys_ids.
A colleague worked it using a script Include which I'll attach here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2024 10:23 PM
We created a new Field Style (sys_ui_style)
Incident - table
Number - field
Value to look up Watch_list ONLY:
Condition= "javascript: new global.OMGIncidentUtils().watchlistUpdatedIncident(current.sys_id) ==true;"
//-----Script include
// Client Callable, All Application Scopes
//API Name - global.OMGIncidentUtils
//Name - OMGIncidentUtils
var OMGIncidentUtils = Class.create();
OMGIncidentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
watchlistUpdatedIncident: function(sysID) {
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', sysID);
incidentGR.query();
if (incidentGR.next()) {
//Watchlist comma seperated into an array
var watchlistArr = incidentGR.watch_list.split(',');
var watchListUserIds = watchlistCheck(watchlistArr);
var userInWatchlist = validationWatchlist(incidentGR.sys_id, watchListUserIds);
return userInWatchlist;
}
function watchlistCheck(arrayList) {
var watchlistDotArr = [];
for (i = 0; i < arrayList.length; i++) {
var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id', watchlistArr[i]);
userGr.query();
if (userGr.next()) {
watchlistDotArr.push(userGr.user_name);
}
// gs.info('The user ids for the watchlist members: ' + watchListDotArr);
}
return watchlistDotArr;
}
function validationWatchlist(recordId, listArr) {
var inGr = new GlideRecord('incident');
inGr.addEncodedQuery('sys_idSTARTSWITH' + recordId + '^sys_updated_byIN' + listArr);
inGr.query();
if (inGr.next()) {
return true;
} else {
return false;
}
}
},
type: 'OMGIncidentUtils'
});