- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 04:04 PM
So I need to filter this reflist.
Does anyone know where I can filter this? We only use a few of the classes and I don't want users select the wrong ones. They will be empty.... but it would lead to confusion if they still 600 classes ... when we only use about 15 for now.
this is url that the link brings up
<a id="lookup.child_table_field" tabindex="-1" class="icon-search btn btn-default sn-tooltip-basic" title="Lookup using list" onclick="mousePositionSave(event);reflistOpen( 'child_table_field', 'not', gel('child_table_fieldTABLE').value, '', 'false', 'QUERY:super_class.nameINSTANCEOFcmdb_ci^ORname=cmdb_ci', 'super_class.nameINSTANCEOFcmdb_ci^ORname=cmdb_ci', '')"><span class="sr-only">Lookup using list</span></a>
I found references to reflistOpen in some templates... but not where to pass filters into it.
thanks for any help
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 06:45 PM
There's no way to get to that filter directly to modify it, so you have to detect (and modify) the query that returns those values. You should be able to accomplish this with a business rule on the 'sys_db_object' table. The business rule will have a 'When' value of 'Before' and the 'Query' checkbox checked. It will identify this specific query and then restrict it a bit further with your own custom encoded query to return just the CI types you want. You should just have to set this up and then add your own encoded query with your CI types. The included script here shows you how you could restrict this to Server and Business Service CIs. Here is the script...
(function executeRule(current, previous /*null when async*/) {
// Adjust the list of CI classes returned in 'Add' CI dialog
// Get URL parameter values so we can identify just this query
var qual = RP.getParameterValue('sysparm_additional_qual');
var target = RP.getParameterValue('sysparm_target');
// If we find a match restrict the query
if (qual.indexOf('cmdb_ci') > -1 && target == 'child_table_field') {
// Add custom encoded query for the 'sys_db_object' table here
current.addEncodedQuery('super_class.nameINSTANCEOFcmdb_ci_server^ORname=cmdb_ci_service');
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 06:45 PM
There's no way to get to that filter directly to modify it, so you have to detect (and modify) the query that returns those values. You should be able to accomplish this with a business rule on the 'sys_db_object' table. The business rule will have a 'When' value of 'Before' and the 'Query' checkbox checked. It will identify this specific query and then restrict it a bit further with your own custom encoded query to return just the CI types you want. You should just have to set this up and then add your own encoded query with your CI types. The included script here shows you how you could restrict this to Server and Business Service CIs. Here is the script...
(function executeRule(current, previous /*null when async*/) {
// Adjust the list of CI classes returned in 'Add' CI dialog
// Get URL parameter values so we can identify just this query
var qual = RP.getParameterValue('sysparm_additional_qual');
var target = RP.getParameterValue('sysparm_target');
// If we find a match restrict the query
if (qual.indexOf('cmdb_ci') > -1 && target == 'child_table_field') {
// Add custom encoded query for the 'sys_db_object' table here
current.addEncodedQuery('super_class.nameINSTANCEOFcmdb_ci_server^ORname=cmdb_ci_service');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 09:40 AM
I really appreciate the reply... not sure how you guys come up with these workarounds.. 🙂
I put in the BR.. added some infomessage debug content... I can see where it sees the URL and runs the BR.. but the query never changes
My goal here... when you click the Class search.. only those tables with >0 records will show up... I'll do that via the SI I created... but wanted to get it working first. Any insight?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 10:25 AM
That's a much more expensive transaction. It would require you to query 700 CMDB tables individually to get a row count and then add all of those table names into a query string. This method isn't as dynamic, but will be drastically better performance-wise. The evidence of the query changing will be that the table selector will only show around 40 tables to choose from (with the sample query in my script) instead of 600-700. How many rows are returned in that table selector popup with the query in place vs. without?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 01:12 PM
So... not sure if there was a caching issue... as I, like most, work in many tabs... but now it did restrict the query. I had tried enough to need to add the infomessage lines... not sure what happen. So this is what I'm doing..
I have a SI (base script is from here) I switched it from a getRowCount to a GlideAggregate
called ListPopulatedCiTables
getFilledCiTables: function() {
var table = new TableUtils("cmdb_ci");
var return_string = "";
var table_string = String(table.getAllExtensions());
var mod_table_str = table_string.slice(1, -1);
var table_array = mod_table_str.split(",");
for(var i in table_array){
var table_name = '';
if(table_array[i].indexOf(" ") == 0)
table_name = table_array[i].slice(1);
else
table_name = table_array[i];
var cis = new GlideAggregate(table_name);
cis.addQuery('operation_status','!=','retired');
cis.addAggregate('COUNT');
cis.query();
if(cis.next()){
if (cis.getAggregate('COUNT') > 0) {
return_string += 'name=' + table_name + '^OR';
}
}
}
//removes the last ^OR
return_string = return_string.slice(0,-3);
return return_string;
Business Rule ( Before/Query)
(function executeRule(current, previous /*null when async*/) {
// Adjust the list of CI classes returned in 'Add' CI dialog
// Get URL parameter values so we can identify just this query
var qual = RP.getParameterValue('sysparm_additional_qual');
var target = RP.getParameterValue('sysparm_target');
// If we find a match restrict the query
if (qual.indexOf('cmdb_ci') > -1 && target == 'child_table_field') {
current.addEncodedQuery(new ListPopulatedCiTables().getFilledCiTables());
}
})(current, previous);
This populates the list... currently only 83 tables. The response time isn't great... I knew it wouldn't be... I may think about having something that runs that SI a few times a day and populates something more static. But it's not horrible and we need to limit confusion for now.