Xpages, hide whens formulas, and user roles

On February 20, 2009, in Uncategorized, by Mark Hughes

I needed to hide a button and since you cant simply put in @isnotmember(“[Admin]”;@userroles)
i had to find a different way to find out if the user was a member of that role, here is what i came up with.

//get the database
db1 = session.getDatabase(“server1″,”database.nsf”)

//get the acl
acl1 = db1.getACL()

//get the current users access
personalentry = acl1.getEntry(session.getEffectiveUserName())

//check if role is enabled

this will return a true or false and calculate the hide when


8 Responses to Xpages, hide whens formulas, and user roles

  1. John Mackey says:

    Hi Mark,

    Your approach is probably shorter, but I wanted to point out another way to access roles that might be useful:

    there is a DirectoryUser object that can provide the roles for a user. Here’s an example:

    var roles = context.getUser().getRoles().toArray();

    Then you can loop through the array or use @IsMember to check if the role exists for the user.


  2. Tim Tripcony says:

    Another issue with .isRoleEnabled is that this only supports users listed explicitly in the ACL. In addition to John’s approach, here’s what I’ve been using:


    Since .queryAccessRoles returns a vector, there’s no need to loop through an array; you can just chain .contains and pass it the role name you’re validating.

  3. Tim Tripcony says:

    Looks like the CSS cut off the end of the code example:


  4. Mark Hughes says:

    Changed theme for better css

  5. John Mackey says:

    @Tim, very cool. So, since getRoles() returns a java.util.List, I can just use the contains() also. Such as:


  6. Tim Tripcony says:

    @John, I like yours better… it’s shorter. :)

  7. Fred says:

    If the application is ment for Notes client it is worth being aware that context.getUser() requires server access while database.queryAccessRoles(session.getEffectiveUserName()) also works offline . . .

  8. Karthik says:

    How to get the role if a person’s name is not listed in ACL, but he is in one of the group.

Leave a Reply

Your email address will not be published. Required fields are marked *