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

Colleen
Tera Expert

I have the same issue.  Have you found a solution to selecting / querying an extended table field with GlideQuery ?

Robert H
Mega Sage

Hello @XavierCalder ,

 

I do not think GlideQuery supports this.

But in your particular example you could use:

...
.where('sys_class_name', 'incident')
.where('state', 1)
...

because "state" is available on the task table and should always have the same value as "incident_state" (unless something was customized). I know it's not a general answer to your question but maybe it helps.

 

Regards,

Robert

Hi Robert,

Unfortunately, no. I was just using the incident state field as an example for my actual use case.

In my case, I'm dealing with the 'cmdb_rel_ci' table, where I need to match CI relationships based on fields not available on the base 'cmdb_ci' table.

Because of the apparent lack of extended table field searching in GlideQuery, I needed to introduce extra steps to search that extended CMDB table explicitly first, then use the resulting Sys IDs to search the 'cmdb_rel_ci' table.

I would prefer to cut out those middle-man steps if possible.

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