Hide a Catalog Item Reference Variable value if the same value is found on another table.

mattmm
Kilo Sage


1. I have a Catalog Item Variable Referencing the cmdb_ci_server table's name field (e.g. value "WindowsServer1" ).

 

2. I also have another table cmdb_group_contains_ci table with a reference field called configuration_item, referencing the cmdb_ci table's 'name' field (e.g. value "LinuxServer1")

 

My Variable is currently showing all name values in the cmdb_ci_server table (point 1. above), but I want to exclude/hide any values that are already present on the cmdb_group_contains_ci table (point 2. above)

 

.....so that a user cannot choose a server (name) that already exists on cmdb_group_contains_ci table.

 

I am hoping someone can point me in the direction of the right thing to do and also a possible script/Ref qualifier, or the like, to do this?

 

Thankyou in advance!

10 REPLIES 10

Thanks @Community Alums , unfortunately this still doesn't work

 

mattmm_0-1714479199097.pngmattmm_1-1714479217495.png

 

@mattmm 

Please modify below function as below and try once

 

getAvailableServerCI: function() {
var arr = [];
   var groupContainsCI = this.getGroupContainsCI();
gs.info("groupContainsCILog "+groupContainsCI);
   var gr = new GlideRecord('cmdb_ci_server');
   gr.addQuery('name', 'NOT IN', groupContainsCI);
   gr.query();
while(gr.next()){
arr.push(gr.sys_id + "");
}
   return arr.toString();
}

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

Community Alums
Not applicable

Try with refQual on the variable pointing to cmdb_ci_server like -

javascript&colon; 'nameNOT IN' + current.variables.<YOUR cmdb_group_contains_ci variable>.

 

Note that you must check the field in the cmdb_ci_server and is it a display value taken from the variable (cmdb_group_contains_ci ) or sys_id. If sys_id change it sys_idNOT IN (possibly its NOTIN - writing this from the top of my mind)

Community Alums
Not applicable

BTW check this article - if you have a related list reference this will be handy

https://www.servicenowelite.com/blog/2022/5/2/related-list-queries-using-gliderecord

Thankyou for persisting with this @Community Alums . Neither of the above work.

The field on cmdb_ci_server table is the 'name' field and is the display field.

The field on the cmdb_group_contains_ci table is the 'configuration_item' field which (when looking at dictionary) references the top level cmdb_ci table's 'name' field.

 However I've just looked at the sysid on the cmdb_ci_server table, and the sysid on the cmdb_group_contains_ci table, and they differ so we have to go by matching the string of 'name' to the string of 'configuration_item'. Which I see is done in the script util, but not sure if possible in just a ref qualifier?