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:32 PM
Hi Satheesh,
That is an example script. Basically i need to orderBy for the joined table so that my results shows in the order instead of random order.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2019 10:35 PM
based on my understanding I have created a script that will give the required result.
try this scripts backgriund
var gr = new GlideRecord('incident');
gr.addEncodedQuery('problem_id.active=true^active=true');
gr.orderBy('problem_id');
gr.query();
while (gr.next()) {
gs.info("Incident : "+ gr.number +" Related problem:" + gr.problem_id.number );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2019 10:43 PM
Hi Satheesh,
Basically below is my original post where i need help.:
Can you check this?