Lookup select box not working as expected.

gjz1
Giga Expert

Hello,

I have a catalog item with a requirement to allow the user to add the CI that is impacted.  To meet this requirement I created two variables, a reference variable on sys_db_object to get the classes and a lookup select box variable to select the cmdb_ci based on the class selected in the first variable. For example, the user should be able to select "Server" (which is cmdb_ci_server) as the class to limit the CI (cmdb_ci) list to just records from cmdb_ci_server.

However, I'm having several issue with the lookup select box. 

1. It takes forever to load the catalog item form.  If I remove the configuration item variable it loads fine so I assume it has something to do with the number of rows in cmdb_ci.  Does a lookup select box always load all values when loading the form?  I don't want the configuration item variable to load any data until the "class" is picked in the 1st variable.

2. The configuration item variable doesn't appear to use the reference qualifier at all.  I added a logging row to verify it is calling the script include but I never see the log in the script log.

Because there isn't any class table (that I'm aware of) to select which cmdb_ci record you want I had to use sys_db_objects to get the "class" (the ci table name) in my first variable to use as a limit in the 2nd variable on the cmdb_ci table (ci table name from first variable = sys_class_name).  If anyone knows a better way to accomplish the same thing please let me know.

Here are my variables:

find_real_file.png

Class name variable:

find_real_file.png

Configuration item variable:

find_real_file.png

find_real_file.png

Script include:

getCIs: function(tableID,CIdata) {
// get the table name that was selected in the catalog
gs.log('### in ci function: ' + ci_table);
var cis = [];
var tbName = '';
var tb = new GlideRecord('sys_db_object');
tb.addQuery('label', ci_table);
tb.query();
while(tb.next()) {
tbName = tb.label;
gs.log('### table: ' + tbName);
}

// now search cmdb_ci to find all records that match the table name
var cmdb = new GlideRecord('cmdb_ci');
cmdb.addQuery('sys_class_name', tbName);
cmdb.query();
while(cmdb.next()) {
cis.push(cmdb.sys_id.toString());
}
if(CIdata)
cis.push(CIdata);
return 'sys_idIN'+cis.toString();

},

Catalog item:

find_real_file.png

The list isn't limited to servers:

find_real_file.png

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

You don't need a script include for that.

 

I would suggest changing the class name variable to a lookup variable and set the lookup value field in it to name

 

Your reference qualifier in base ci should be .

javascript:'sys_class_name='+current.variables.class_name

 

and variable attribute should be

ref_qual_elements=class_name


Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjiv for the response but that is not working for us.

I originally had set up the variables the way you suggested, but it takes  2- 3 minutes for the form to load because it appears to load all cmdb_ci records before the form is visible.  I'm trying to limit the cmdb_ci records to load only when a value is selected in the class field.  It's not acceptable to wait several minutes to load the form and then wait again when it selects the rows I want based on the class.

What happens if you do the following.

 

Change the class name variable to a lookup variable instead of reference and set the lookup value field in it to name

 

Change the Base CI field to a reference field instead of lookup.

Your reference qualifier in base ci should be .

javascript:'sys_class_name='+current.variables.class_name

 


Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjiv, that is a lot better.  We are having performance issues with ServiceNow today so I can't tell yet if it's the solution, but I think it will be.