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 joining more than two tables

Rafal Rataj1
Giga Expert

For a widget I need to have a glideRecord with results of Service Offerings, 

however due to the amount of data it needs to be restricted to the subscribed users, 

those subscriptions are done in various tables (cmdb_subscriber, service_subscribe_sys_user)

// https://docs.servicenow.com/bundle/madrid-it-service-management/page/product/service-portfolio-manag... 

so using a addJoinQuery it is simple to join 2 tables 

var so = new GlideRecord('service_offering');
    var s= so.addJoinQuery('cmdb_subscriber','sys_id','item');
          s.addOrCondition('user', gs.getUserID());
     so.query();

 

that works, returning the desired value, 

now I want to jon the next table and filter it as well fo the current user, this is not working 

var so = new GlideRecord('service_offering');
   var s= so.addJoinQuery('cmdb_subscriber','sys_id','item');
   var su= so.addJoinQuery('service_subscribe_sys_user','sys_id','service_offering');

s.addOrCondition('user', gs.getUserID());
su.addOrCondition('sys_user', gs.getUserID());

so.query();

it is acting like an AND query instead of an OR 

is there any other addJoinQuery  for left joins? 

 

2 REPLIES 2

Kalyani Jangam1
Mega Sage

Hi @Rafal Rataj1 

su.addOrCondition('sys_user', gs.getUserID()); why we use this function as we already use s.addOrCondition('user', gs.getUserID()); to take user record.

jaheerhattiwale
Mega Sage

@Rafal Rataj1 Please try the below code. I have tested and its looking good.

 

var so = new GlideRecord('service_offering');
   var s= so.addJoinQuery('cmdb_subscriber','sys_id','item');
   var su= so.addJoinQuery('service_subscribe_sys_user','sys_id','service_offering');

so.addOrCondition('user', gs.getUserID());
so.addOrCondition('sys_user', gs.getUserID());
so.query();
 
Please mark correct answer if this solves your issue
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023