Finding out if the current user has a given role, in Lotus Script

Yet another Another . Please note some small corrections to last weeks examples (DBlookup’s to leverage the Name and Address book). Oh the dangers of coding when tried.

Now for this weeks mistake in progress tip:

In Formula language, when we want to have results (like hide-when’s) based on a role it’s common to use “@Contains(@UserRoles;”ADMIN)” , but there is no native LotusScript way to do this…however it is possible to use a simple Evaluate() to ask”does this user have the role [XXX]”

for example:

1
2
3
 If IsInRole("[Admin]") then
       ' do stuff
endif

using this LotusScript function I’ve re-invented several times :

1
2
3
4
5
6
7
8
9
10
11
Function IsInRole (RoleName As String) As Integer
        IsInRole = False
        Dim userRoles As Variant   
        userRoles = Evaluate("@UserRoles")
        Forall role In userRoles
                 If Ucase(role) = Ucase(RoleName) Then
                        IsInRole = True
                        Exit Forall
                 End If
         End Forall
End Function

Two things to be aware of : A) for this to work on the web the agent has to “Run as user”, otherwise it will show the roles of the id that signed the web agent. B) On a a local database make sure you have “Enforce a consistent Access Control List across all replicas” in effect.

4 Replies to “Finding out if the current user has a given role, in Lotus Script”

  1. If ND6 or later the ArrayGetIndex could be used instead of the ForAll loop
    isInRole = Not Isnull( Arraygetindex( userRoles , RoleName , 5 ) )

    The third parameter so the compare is case insensitive and pitch insensitive!

    [good point Chad! ]

  2. Arraygetindex was there in R5 as well, but it seems to have been a very much underused function. And in ND6.5 and higher, there’s NotesDatabase.QueryAccessRoles to replace the Evaluate(@UserRoles).

    [Ian : Good Points Stan! many thanks…]

  3. Pingback: False Positives » Using LotusScript Evaluate to save lots and lots of work

  4. Pingback: False Positives » Blog Archive » Opening a Lotus Notes Profile Document in Read Only mode

Leave a Reply to Stan Rogers Cancel reply