User & Group Access

Utkarsha
Tera Contributor

Hello Experts,

I have two custom fields on form for allowed users and allowed groups, I have written before query business rule to restrict the access, but the condition which I've applied is not working for all users.

Could anyone please figure out where I'm getting wrong here?

Business rule -Type: Before, Query

condition:

Code:

if ((!gs.hasRole('admin') && gs.getSession().isInteractive()) || (gs.getUserID().isMemberOf(current.u_allowed_groups.toString()) && gs.getSession().isInteractive())) { 
var u = gs.getUserID(); //Get the sys_id value of the current user

current.addQuery('u_confidential', false).addOrCondition('u_allowed_groupsIN', gs.getUser().getMyGroups().toArray().join());
//var q = current.addQuery('u_allowed_users', u); /
//q.addOrCondition('u_confidential',false); 
gs.addInfoMessage('query restricted to user: ' + u);
}

As per the requirement, the system should check either user is present on allowed users field or he is part of the group present in allowed groups field.
 
Any sort of help here is greatly appreciated here.
 
Thank you!
1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

Your IF condition doesn't seems correct, the brackets ")"closing  are more then "(" the openings.

Check your condition.


Raghav
MVP 2023

View solution in original post

2 REPLIES 2

RaghavSh
Kilo Patron

Your IF condition doesn't seems correct, the brackets ")"closing  are more then "(" the openings.

Check your condition.


Raghav
MVP 2023

Suyog Aptikar
Giga Guru

if ((!gs.hasRole('admin') && gs.getSession().isInteractive()) || (gs.getUserID().isMemberOf(current.u_allowed_groups.toString()) && gs.getSession().isInteractive()))

 

Can you try using getUser() instead of getUserID(), this should correct your code working.

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog