addJoinQuery fetch both tables fields

Arul Veeraragha
Kilo Contributor

Hi,

I have Table1 (Primary) and Table2 (Secondary), I need to fetch both tables fields using addJoinQuery() with GlideRecord(), Please suggest what is the other way work around in Server Script?

Thanks

Arul

1 ACCEPTED SOLUTION
4 REPLIES 4

Additionally you can also add related list condition via addEncodedQuery 😉

Example when querying for active problems where there is at least on related incident of priority 1:

var gr = new GlideRecord("problem");
gr.addEncodedQuery("active=true^RLQUERYincident.problem_id,>=1^priority=1^ENDRLQUERY");
gr.query();

@Arul Veeraraghavan 

Thanks for marking my response as helpful.

Did my reply answer your question?

If so, please mark it correct so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Daniel Oderbolz
Mega Sage

Well, GlideRecord does not really allow you to do real joins. What you can do is for example find records where a reference has a certain value, but you cannot directly read the data of the refereced table (unless you use getReferenceRecord).

To perform proper joins as you would expect them in a decent database, create a view and join the tables there:

Database views | ServiceNow Docs

 

Best
Daniel