GlideRecord LEFT JOIN two tables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2016 06:42 AM
Hi guys,
How Can I write a LEFT JOIN in ServiceNow?
Exist GlideRecord's method called addJoinQuery for INNER JOIN, but not LEFT JOIN.
Can you help me?
Thanks,
Gaetano
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2016 07:03 AM
Consider taking a look at Database Views and query against that with a traditional GlideRecord query.
http://wiki.servicenow.com/index.php?title=Database_Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2016 07:09 AM
I believe it does not work. I must create a script fix, and not a database view.
Table1:
sys_id,field1,field2 ...
Table2:
sys_id,field1, field2, sys_id_table_1
I have to have all record of the table1 with sys_id_table_1 is null.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 10:13 AM
how did you implement this ?
I need to join two tables in Scripted REST API .. ..!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2020 06:29 AM
This is what seems to be working for me (running in Xplore):
var userId = gs.getUserID();
var grSCPE = new GlideRecord('__table1__');
var grJoin = grSCPE.addJoinQuery("__m2mTable__", "sys_id", "__m2mLinkingField__");
grJoin.addCondition("__m2mConditionField__", userId);
// needs to work as OR, so we use New Query
grSCPE.addEncodedQuery("NQ__table1ConditionField__=" + userId);
grSCPE.query();
while (grSCPE.next()) {
gs.addInfoMessage('number: ' + grSCPE.getValue('number'));
}
grSCPE;