Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideRecord LEFT JOIN two tables

Gaetano De Mitr
ServiceNow Employee
ServiceNow Employee

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

5 REPLIES 5

Thanks! I was looking for this too.

For me to make this work with a Database View, I did like the following example:

1. Created a DB View with one View Table without Where Clause: [sys_user]

2. Created before Query business rule:

var join = current.addJoinQuery('ldap_import', 'user_user_name', 'u_samaccountname');
join.addCondition('sys_created_on', 'ON', 'Today@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()'); //INNER JOIN

current.addQuery('user_active', 'true'); //ADD where clause to [sys_user]

current.addEncodedQuery("NQuser_user_nameISNOTEMPTY^user_active=true"); //LEFT JOIN