Adding Field Style to Incident List View When a Watch List User Makes an Update

steve_gannon
Tera Expert

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)

  1. 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.
  2. 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.
1 ACCEPTED SOLUTION

steve_gannon
Tera Expert
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'
});

View solution in original post

3 REPLIES 3

1__AnithaHV
Kilo Sage

Hi @steve_gannon 

 

Please use the below conditions and check.

Example 1:

Condition: 

 (current.caller_id.user_name == current.sys_updated_by) || (current.watch_list.indexOf(current.sys_updated_by) > -1)

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

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

steve_gannon
Tera Expert
We created a new Field Style (sys_ui_style)
Incident - table
Number - field
Value to look up Watch_list ONLY:
Condition= "javascript&colon; 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'
});