GlideQuery - Query Extended Table

XavierCalder
Tera Contributor

With GlideRecord, there's a notation that you can use to query a field of an extended table - ref_(extended_table_name).

For example:

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

 

Is there an equivalent notation when using GlideQuery?

If I try to use similar notation as the GlideRecord example above with GlideQuery, an error is thrown.

var taskGq = new GlideQuery('task')
	.where('ref_incident.incident_state', '1')
	.selectOne('number')
	.get();

// ERROR THROWN: Cannot dotwalk field 'ref_incident' on table 'task': not a reference field

 

1 ACCEPTED SOLUTION

Hello @XavierCalder ,

 

Understood. Unfortunately GlideQuery still has some limitations, including missing support for encoded queries, which I believe includes the "'ref_{table}.{field}" syntax.

But instead of doing those extra steps that you mentioned I would just go back to using good old GlideRecord for this particular requirement.

 

Regards,

Robert

View solution in original post

6 REPLIES 6

Hi @Robert H,

Unfortunately, no. I was simply using the incident state field to illustrate my problem.

My actual use case is with the 'cmdb_rel_ci' table. I had a need to search for CI relationships using GlideQuery, based on a field available only on an extended CMDB table, not on the base 'cmdb_ci' table.

Because of the apparent lack of extended table searching in GlideQuery, I needed to introduce an intermediate step to search that extended table explicitly first, then pass the resulting Sys IDs to the 'cmdb_rel_ci' search. It got the job done, but extended table searching would have been more efficient.

Hi @Robert H,

Unfortunately, no. I was simply using the incident state field to illustrate my problem.

My actual use case is with the 'cmdb_rel_ci' table. I had a need to search for CI relationships using GlideQuery, based on a field available only on an extended CMDB table, not on the base 'cmdb_ci' table.

Because of the apparent lack of extended table searching in GlideQuery, I needed to introduce an intermediate step to search that extended table explicitly first, then pass the resulting Sys IDs to the 'cmdb_rel_ci' search. It got the job done, but extended table searching would have been more efficient.