GlideRecord joining more than two tables

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 06:07 AM
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)
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 09:56 PM
su.addOrCondition('sys_user', gs.getUserID()); why we use this function as we already use s.addOrCondition('user', gs.getUserID()); to take user record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 10:54 PM
@Rafal Rataj1 Please try the below code. I have tested and its looking good.
ServiceNow Community Rising Star, Class of 2023