Query in groovy script of Access Group Constraint

How to run query inside a groovy script for an access group constraint?

I tried using transactional / persistence object like in groovy script for a Report but it’s not working for access group constraint.

Thanks.

I would not recommend using queries or any other heavy-weight operations like invoking services in constraints, as you can ruin the performance completely. In-memory constraints are called for each object in object graph many times, so they should only run checks against already loaded object properties. In order to avoid “unfetched attribute” errors, use PersistenceHelper.isLoaded().