- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 01:33 PM
Hello,
I am working on a requirement .
- Create a read ACL for the users where the assignment group's child groups (haystack) are part of user's group (needle). If yes, allow read access.
- Read ACL is in scoped application (customer service). Is this possible to get group array list without using glideRecord query (on group table) from scoped application (customer service) ?
Any help would be greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 10:44 PM
Hi @Sathiskumar_D ,
You can use below scrip in ACL.
var user = gs.getUser();
var assignmentGroupSysId = current.assignment_group
var userGroups = user.getMyGroups();
gs.print('parent ' + userGroups);
var childGroups = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('parent',assignmentGroupSysId);
gr.query();
while(gr.next()) {
childGroups.push(gr.sys_id.toString());
}
for (var i = 0; i < childGroups.length; i++) {
if (userGroups.indexOf(childGroups[i]) !== -1) {
return true;
}
}
return false;
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 11:07 PM
you can create table level READ ACL with advanced script as this
Use ArrayUtil to check if group contains in another array
var groupsArr = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
var childGroupsArray = [];
var childRec = new GlideRecord('sys_user_group');
childRec.addQuery('parent', current.assignment_group);
childRec.query();
while(childRec.next()) {
childGroupsArray.push(childRec.getUniqueValue());
}
var arrayUtil = new global.ArrayUtil();
var finalArray = arrayUtil.intersect(childGroupsArray, groupsArr);
answer = finalArray.length > 0;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 08:34 PM
you can get logged in user's group in both global + scoped all using this
var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
gs.info(groups.length);
Now to get child groups, you will have to use GlideRecord and it should work from both global + scoped app
what did you try so far and what didn't work?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 11:07 PM
you can create table level READ ACL with advanced script as this
Use ArrayUtil to check if group contains in another array
var groupsArr = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
var childGroupsArray = [];
var childRec = new GlideRecord('sys_user_group');
childRec.addQuery('parent', current.assignment_group);
childRec.query();
while(childRec.next()) {
childGroupsArray.push(childRec.getUniqueValue());
}
var arrayUtil = new global.ArrayUtil();
var finalArray = arrayUtil.intersect(childGroupsArray, groupsArr);
answer = finalArray.length > 0;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 10:44 PM
Hi @Sathiskumar_D ,
You can use below scrip in ACL.
var user = gs.getUser();
var assignmentGroupSysId = current.assignment_group
var userGroups = user.getMyGroups();
gs.print('parent ' + userGroups);
var childGroups = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('parent',assignmentGroupSysId);
gr.query();
while(gr.next()) {
childGroups.push(gr.sys_id.toString());
}
for (var i = 0; i < childGroups.length; i++) {
if (userGroups.indexOf(childGroups[i]) !== -1) {
return true;
}
}
return false;
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 06:28 AM
Thanks @Ankur Bawiskar && @Runjay Patel Both solutions worked for me..I got the same solution before..It is working now..