Access control help

Andrew_TND
Mega Sage
Mega Sage

I've created a "READ" access control which has worked...ish. For some reason its now showing a blank placeholder where the record should be, any ideas how I can just remove this completely?

I did try and configure it instead however the dynamic "is one of my groups" didnt seem to work so had to go down the scripting route.

Andrew_TND_0-1735559547254.png

Andrew_TND_1-1735559675736.png


Script condition

 

answer = true;

if (current.u_nda) {
	var group = current.u_authorized_group;

	if (!gs.getUser().isMemberOf(group)) {
		answer = false;
	}
}

 

1 ACCEPTED SOLUTION

Andrew_TND
Mega Sage
Mega Sage

Hey all, I managed to get it working using "addEncodedQuery()" which is actually really simple.

 

//When to run: Before
//Order: 1000
// Query: True

(function executeRule(current, previous) {
    var query = '';
    query = "u_authorized_groupDYNAMICd6435e965f510100a9ad2572f2b47744^ORu_authorized_groupISEMPTY";
    current.addEncodedQuery(query);
})(current, previous);

 


Thank you everyone for your help! 

View solution in original post

14 REPLIES 14

@Andrew_TND 

got it

That's how ACLs work.

If table has 100 records and only 10 satisfy then those 10 records are scattered and user has to scroll to the next page

To overcome this you can use query BR on that table and have similar query

BR Condition: gs.getSession().isInteractive()

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
    current.addQuery('u_authorized_group', 'IN', groups);
    current.addQuery('u_nda', true);

})(current, previous);

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

Hi Ankur, thanks for coming back to me. Unfortunately neither have worked, I'm going to give another crack at it however if you come up with any other ideas in the meantime I'm all ears! 😁

@Andrew_TND 

did you try the below script?

Also are you sure you have table.None READ ACL on your table?

Are you having the same issue which I mentioned above i.e. records are scattered on next pages and user has to scroll?

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

Currently its * I did try "None" however it stops working when I do.

@Andrew_TND 

you should have table.None READ ACL with same advanced script

table.* READ is not required.

Did you create query BR and verify it? did you try the updated query BR?

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
    current.addEncodedQuery('u_nda=true^u_authorized_groupNOT IN' + groups).addOrCondition('u_nda', false);

})(current, previous);
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader