We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

GlideRecord LEFT JOIN two tables

GaetanoD
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