- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 04:10 PM
hi all,
I'm looking run a GlideRecord query where I have a user's sys_id, and I check the [sys_user_grmember] table to see if the user is in a group. But then I also want to check whether that group is of a certain type, by using an addJoinQuery to the [sys_user_group] table to check the "type" field. I pulled some info from servicenow Docs, but unclear how to use it in this context.
Is it possible to use addJoinQuery in this context? One thing that I wonder about whether it's a problem if my field on the [sys_user_grmember] table is a reference field, and the field that matches on the [sys_user_group] field is a string field...will this prevent addJoinQuery from working? OR...Anyone see what's missing in my script? thanks!
//lookup for assignment group
var grp = new GlideRecord('sys_user_grmember');
var grpSQ = grp.addJoinQuery('sys_user_group');//to check the 'type' of the group
//where the gr user from above is the user of the group
grp.addQuery('user',gr.sys_id);//this is the sys_id I've gotten from an earlier GlideRecord
//add the condition that the group is one of 3 types; itsm, hr, or erp_sm
grpSQ.addCondition('typeLIKEitsm');
grp.query();
if (grp.next()) {
current.assignment_group = grp.group;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2021 07:50 AM
I don't think you need to use the addJoinQuery() method for this. Note that addQuery() supports dot-walking. You should, therefore, be able to achieve what you want with a simple query like this:
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user', '<sys_id_of_the_user>');
grp.addQuery('group.type', 'CONTAINS', '<sys_id_of_itsm_type>');
grp.query();
if (grp.next()) {
current.assignment_group = grp.group;
}
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2021 08:40 AM
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2021 12:48 PM
thanks Slava!