The CreatorCon Call for Content is officially open! Get started here.

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try going below links for help

addJoinQuery(String table)

Help with addJoinQuery()

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try going below links for help

addJoinQuery(String table)

Help with addJoinQuery()

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Daniel Oderbolz
Kilo 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


If this post was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel