Help with addJoinQuery()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2019 10:24 AM
Hi Team,
I need to access object of the join table. Any help?
For eg: if we see below example, how can i access fields of incident table?
Also orderBy is not supposed to be working. When i am trying to print the order, it is coming as undefined:
// Look for Problem records that have associated Incident records
var gr = new GlideRecord('problem');
var grSQ = gr.addJoinQuery('incident');
// Where the Problem records are "active=false"
gr.addQuery('active', 'false');
// And the Incident records are "active=true"
grSQ.addCondition('active', 'true');
grSQ.orderBy('order');
// Query
gr.query();
// Iterate and output results
while (gr.next()) {
gs.info("Order is: " + grSQ.order);
gs.info(gr.getValue('number'));
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2019 10:29 AM
Hi,
The addJoinQuery allows you to fetch the records based on the join (it is like subquery). You can access the fields only from the table on which the GlideRecord is initialized.
Mark the comment as a correct answer and helpful if you find this helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2019 10:34 AM
So if i need to orderBy in the subquery it will not work?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2019 10:50 AM
No, it wont. The orderBy is used to display the results in a specific order. Since addjoinQuery is not the end result, orderBy does not work there. So in your example, you have to use OrderBy on the gr object.
Mark the comment as a correct answer and helpful if you find this helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2019 10:25 PM
Your script is not correct, share what exactly you are looking so that your script can be fixed!