Help with addJoinQuery()

ServiceNow SA
Kilo Guru

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'));
}

 

7 REPLIES 7

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.

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 );
}

Hi Satheesh,

Basically below is my original post where i need help.:

https://community.servicenow.com/community?id=community_question&sys_id=dc1a3d651bddcc10d01143f6fe4b...

Can you check this?