- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 07:48 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 08:02 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 08:02 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 08:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 08:13 AM
You are welcome! Happy to help!