ACL with GlideRecord

JohnnySnow
Kilo Sage
Hi Team,
 
I'm writing an ACL and had to use GlideRecord, I have read that it is not a best practice to use GR in
the ACL scripts, but I'm not sure how to handle this scenario. Can some one please guide?

 

answer = false;
var assignmentGroups;
var groupArray = [];


if (current) {

    assignmentGroups = current.getValue('related_assignment_groups').toString();// a list field which holds all the related assignment groups worked on that ticket
    groupArray = assignmentGroups.split(',');

//To check if the current user is a manager of any of the related groups if yes, then show the record
    var groupGR = new GlideRecord('sys_user_group');
    groupGR.addQuery('manager', gs.getUserID());
    groupGR.addQuery('sys_id', 'IN', groupArray);
    groupGR.query();

    if (groupGR.next()) {
        answer = true;
    } else {

		//to check if the user is a member of any of the related groups list.
        answer = groupArray.some(function(group) {
            return gs.getUser().isMemberOf(group.trim());
        });
    }
  

}

 

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.
6 REPLIES 6

Thanks @Maik Skoddow that makes sense!

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

Sandeep Rajput
Tera Patron
Tera Patron

@JohnnySnow You can replace the GlideRecord query by creating Dynamic filters. Please refer to the dynamic filter for One of My Assignment groups and replicate the same logic for related_assignment_group. Similarly, for the manager you can create another dynamic filter which will check Related Assignment Group. Manager is (dynamic) Me. 

 

This will eliminate the need of using repetitive GlideRecord calls in ACL for more information on dynamic filters please refer to https://docs.servicenow.com/bundle/vancouver-platform-user-interface/page/use/using-lists/task/t_Dyn....

 

Hope this helps.