- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 02:54 AM - edited 03-22-2023 02:56 AM
Hi,
I need to restrict item to a catalog item with user criteria.
Only the members groups that have parent "Group A" should have access.
But it seems i have an error in my script or a wrong logic.
checkChildGroups();
function checkChildGroups(){
var arr=[];
var grChilds = new GlideRecord('sys_user_group');
grChilds.addEncodedQuery('parent.sys_id=e272b912db671814c84f2ded0b961985^active=true');
grChilds.query();
while(grChilds.next()){
arr.push(grChilds.name.toString());
}
for(var i=0; i<arr.length; i++){
if(gs.getUser().isMemberOf(arr[i])){
return true;
}
return false;
}
}
Any help would be appriciated.
Regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 03:08 AM
Hi @Nico12 ,
As far as I can read, you don't need a script in user criteria to include child groups in the user criteria. Please see community post back from 2022: Solved: Re: User Criteria group - does it include child gr... - ServiceNow Community
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 03:08 AM
Hi Nico,
Can you try below.
checkChildGroups();
function checkChildGroups(){
var arr=[];
var grChilds = new GlideRecord('sys_user_group');
grChilds.addEncodedQuery('parent.sys_id=e272b912db671814c84f2ded0b961985^active=true');
grChilds.query();
while(grChilds.next()){
arr.push(grChilds.name.toString());
}
for(var i=0; i<arr.length; i++){
if(gs.getUser().isMemberOf(arr[i])){
return true;
}
else{
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 03:08 AM
Hi @Nico12 ,
As far as I can read, you don't need a script in user criteria to include child groups in the user criteria. Please see community post back from 2022: Solved: Re: User Criteria group - does it include child gr... - ServiceNow Community
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 03:26 AM - edited 03-22-2023 03:27 AM
Hi,
i finally succeed to make the script worked :
My return false was not in the right place.
checkChildGroups();
function checkChildGroups(){
var arr=[];
var grChilds = new GlideRecord('sys_user_group');
grChilds.addEncodedQuery('parent.sys_id=e272b912db671814c84f2ded0b961985^active=true');
grChilds.query();
while(grChilds.next()){
arr.push(grChilds.name.toString());
}
for(var i=0; i<arr.length; i++){
if(gs.getUser().isMemberOf(arr[i])){
return true;
}
}
return false;
}
but thanks @AndersBGS I didn't see this post and i will go for your solution.
Regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 03:39 AM
Great to know. Comments before were the same & thus had addded else condition in my comments.