Issue with Advanced Reference Qualifier on List Collector

Kevin Ng
Tera Expert

Hello Dev Community,

 

I've created an advanced reference qualifier for a list collector variable in a catalog item that I'm getting inconsistent output from. This list collector is looking at the cmdb_ci_win_server table and I'm attempting to limit results to only CIs that the current user is a member of the Support Group (support_group) for. 

 

When I run the reference qualifier code in a background script I am getting the complete list of CIs for a user, but in the Catalog Item the results are not incomplete. 

 

This is the reference qualifier code...

javascript: (function() {
    var user = gs.getUser(); // Get the current user
    var ciSysIds = []; // Initialize an array to store the Sys IDs of CIs

    // Create a GlideRecord for the cmdb_ci_win_server table
    var ciGR = new GlideRecord('cmdb_ci_win_server'); 
    ciGR.addQuery('support_group', '!=', ''); 
    ciGR.query(); // Query for CIs

    while (ciGR.next()) {
       
        if (user.isMemberOf(ciGR.support_group)) {
            ciSysIds.push(ciGR.sys_id.toString()); 
        }
    }

    // Return the reference qualifier
    return ciSysIds.length > 0 ? 'sys_id IN (' + ciSysIds.join(',') + ')' : 'sys_id IS NULL';
})();

 

Any help would be appreciated!

 

Kevin

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

That's a lot for a reference qualifier.  It should be technically possible, but with an errant character, space, or line return it will choke.  First try changing the return to 

return ciSysIds.length > 0 ? 'sys_idIN' + ciSysIds.join(',') : 'sys_idISNULL';

If that doesn't work you'll need to put the code in a Script Include and call that, with this same return.

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

That's a lot for a reference qualifier.  It should be technically possible, but with an errant character, space, or line return it will choke.  First try changing the return to 

return ciSysIds.length > 0 ? 'sys_idIN' + ciSysIds.join(',') : 'sys_idISNULL';

If that doesn't work you'll need to put the code in a Script Include and call that, with this same return.

Kevin Ng
Tera Expert

Thank you so much @Brad Bowman  ! That did the trick. 

 

Have a great day!

 

Kevin

You are welcome! Happy to help!