GlideRecord - Query extended table

Justin Lee2
Tera Guru

Sorry for the wordy question...

I am querying a table with GlideRecord.  The table has a reference column to the configuration item table.  I only want to return records where the configured item in that column is a certain type.  (a table that extends config. item)

I successfully achieve this with:  record.addQuery("name_of_ref_col.sys_class_name", "name_of_extended_table");

However, I would like to also filter by a certain column in the extended table.  Note:  This column is not in the configuration item table, it is in a table that extends configuration item - the table I am filtering the results to with the above query.

This does not work:  record.addQuery("name_of_ref_col.my_col", some_val);

Is this possible?  Any suggestions?

 

The exact scenario is:

I am querying Indicator Scores (apm_app_indicator_score) where the configuration item is a Business Capability (cmdb_ci_business_capability).  I want to add a query where Capability.hierarchy_level is 2.

This does not work:  record.addQuery("cmdb_ci_business_app.hierarchy_level", 2) 

1 ACCEPTED SOLUTION

Tony DiRienzo
Giga Guru

You need to reference the extended table in your query condition.  For example, if you were querying on the Task table and you wanted to add a query for Incident State is New (1):

var task = new GlideRecord("task");
task.addQuery("ref_incident.incident_state", "1");
task.query();

So in your case, this should work:

record.addQuery("cmdb_ci_business_app.ref_cmdb_ci_business_capability.hierarchy_level", 2); 

View solution in original post

2 REPLIES 2

Tony DiRienzo
Giga Guru

You need to reference the extended table in your query condition.  For example, if you were querying on the Task table and you wanted to add a query for Incident State is New (1):

var task = new GlideRecord("task");
task.addQuery("ref_incident.incident_state", "1");
task.query();

So in your case, this should work:

record.addQuery("cmdb_ci_business_app.ref_cmdb_ci_business_capability.hierarchy_level", 2); 

Perfect. Thanks Tony!