Get the list of child groups from parent group

Sathiskumar_D
Giga Sage

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.

2 ACCEPTED SOLUTIONS

Runjay Patel
Giga Sage

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

-------------------------------------------------------------------------

View solution in original post

@Sathiskumar_D 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Glad to assist you.