Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Script include's 'activeAnything' query is not passing through the OOB query BR

Shraddha17
Tera Contributor

Hi,

 

There's an OOB BR which prevents itil users to see disabled user records. To bypass this, we have added a condition in this BR to check if the current query contains 'Active Anything' flag as we just need to bypass this one catalog item's reference qualifier.

 

This script is not working for itil users and they are still unable to see disabled user records. What am I missing here ?

 

Here is the BR,

(function executeRule(current, previous /*null when async*/ ) {
    var query = current.getEncodedQuery();
    if (gs.getSession().isInteractive() && !query.includes('activeANYTHING')) {
        current.addActiveQuery();
    }
})(current, previous);
 
 
Here is the advanced reference qualifier,
javascript: new ReferenceQualifiers().test();
 
Here is the script include,
a1: function(_lastUpdatedHoursStr) {
        // gs.log('Ref Inactive _lastUpdatedHoursStr ' + _lastUpdatedHoursStr);

        var queryString = 'activeANYTHING^active=false';

        var userIdArr = [];
        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('active', 'false');
        userGr.addQuery('user_name', 'NOT LIKE', 'ad%');
        userGr.addQuery('user_name', 'NOT LIKE', 'bd%');
        userGr.addQuery('name', 'DOES NOT CONTAIN', 'test');
        userGr.addQuery('u_checktype_type', 'DOES NOT CONTAIN', 'vvv');
        userGr.addNotNullQuery('employee_number');
        userGr.addNotNullQuery('u_num');
        if (_lastUpdatedHoursStr != undefined) {
            var lastUpdatedQueryStr = 'sys_updated_onRELATIVEGT@hour@ago@' + _lastUpdatedHoursStr;
            userGr.addEncodedQuery(lastUpdatedQueryStr);
        }
        userGr.query();
        while (userGr.next()) {
            userIdArr.push(String(userGr.sys_id));
        }

        return queryString + '^sys_idIN' + userIdArr;
    },
 
    b1: function() {

        var userIdArr = [];
        var userGr = new GlideRecord('sys_user');
        userGr.addActiveQuery();
        userGr.addQuery('user_name', 'NOT LIKE', 'ad%');
        userGr.addQuery('user_name', 'NOT LIKE', 'bd%');
        userGr.addQuery('name', 'DOES NOT CONTAIN', 'test');
        userGr.addQuery('u_checktype_type', 'DOES NOT CONTAIN', 'vvv');
        userGr.addNotNullQuery('employee_number');
        userGr.addNotNullQuery('u_num');
        userGr.query();
        while (userGr.next()) {
            userIdArr.push(String(userGr.sys_id));
        }

        return 'active=true^sys_idIN' + userIdArr;
    },
 
    test: function() {

        var userIdArr = [];
        var queryAllStr = '';
        var queryActiveStr = '';
        var queryInactiveStr = '';
        if (this.b1().length > 0) {
            queryActiveStr = String(this.b1());
        }

        if (this.a1('96').length > 0) {
            queryInactiveStr = String(this.a1('96'));
        }

        if (JSUtil.notNil(queryInactiveStr) && JSUtil.notNil(queryActiveStr)) {
            queryAllStr = queryActiveStr + '^NQ' + queryInactiveStr;
        }

        return queryAllStr;
    },
 
1 REPLY 1

drbob
Tera Guru

I've done this before (with the same choice of "activeANYTHING"). Don't have access now but can confirm it _should_ work.

Have you logged the value of "query" in your BR to make sure the "activeANYTHING" is making it through ? Also, log the result of query.includes('...') - in case there's something wacky going on there (I can't recall but isn't the inclusion of "includes()" a newer thing - maybe query BRs don't understand that - have you tried seeing if query.indexOf('...') is "-1" ?