- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 02:59 PM
I am filtering a list collector down to a list of groups that are children of a specific group. Previously the parent/child relationship was 1:1 and it was easy to do:
var grpGR = new GlideRecord('sys_user_group');
grpGR.addQuery('parent', deptName + '_SuggestedDLs');
grpGR.query();
while (grpGR.next()) {
grpList.push(grpGR.sys_id + '');
}
}
return grpList;
However, we now have a many to many relationship so that a group can have many parents. I created a glide list to accommodate this. How can I query for groups where the glide list contains the specific parent group?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 04:07 PM
Hi Pradeep,
Thanks, I got this working. I had to query the parent group first. Regarding the group_sysid, I should have been more clear. The parent group will be dynamic based on the department being passed.
function getDepartmentGroups(deptID){
var grpList = [];
var deptGR = new GlideRecord('cmn_deprtment');
if(deptGR.get(deptID)){
var deptName = DeptGR.name.replace(',', '');//Some of the departments contain commas, but the groups do not
var parentGroup = new GlideRecord('sys_user_group');
parentGroup.addQuery('name', deptName + '_SuggestedDLs');
parentGroup.query();
while(parentGroup.next()){
var grpGR - new GlideRecord('sys_user_group');
var grpGR.addQuery('u_parent, 'CONTAINS', parentGroup.sys_id);
grpGR.query();
while(grpGR.next()){
grpList.push(grpGR.sys_id + '');
}
}
}
return grpList;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 03:20 PM
Hi Robbie,
You have to change 2nd line to
grpGR.addQuery('parent','IN', GROUP_SYSID);
However I would suggest not to hardcode the "GROUP_SYSID" in a variable and instead create a property and then fetch the sys_id via property i.e gs.getProperty('Property Name'); More info here.
Adding a Property - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 04:07 PM
Hi Pradeep,
Thanks, I got this working. I had to query the parent group first. Regarding the group_sysid, I should have been more clear. The parent group will be dynamic based on the department being passed.
function getDepartmentGroups(deptID){
var grpList = [];
var deptGR = new GlideRecord('cmn_deprtment');
if(deptGR.get(deptID)){
var deptName = DeptGR.name.replace(',', '');//Some of the departments contain commas, but the groups do not
var parentGroup = new GlideRecord('sys_user_group');
parentGroup.addQuery('name', deptName + '_SuggestedDLs');
parentGroup.query();
while(parentGroup.next()){
var grpGR - new GlideRecord('sys_user_group');
var grpGR.addQuery('u_parent, 'CONTAINS', parentGroup.sys_id);
grpGR.query();
while(grpGR.next()){
grpList.push(grpGR.sys_id + '');
}
}
}
return grpList;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2018 12:32 PM
Hi Pradeep,
I am trying to hide options on a field of type "list".
I am trying to achieve this on knowledge form.
for a Knowledge Base A, "can read" should display only A,B,C
for a Knowledge Base B, "can read" should display only X,Y,Z
Can read is a field of type list referencing "Uer Criteria"table.
Please assist
Thankyou