Home | Blog Roll |  Link Roll |  Colophon/About| |


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

Posted under Show-n-Tell+Thursday, Lotus Domino, on Wednesday, March 8th, 2006;

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:

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

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

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.

See also

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

  1. Chad Schelfhout Says:

    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. Stan Rogers Says:

    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. False Positives » Using LotusScript Evaluate to save lots and lots of work Says:

    […] One example almost replaces the need for the code in my earlier Finding out if the current user has a given role, in Lotus Script SnTT - which itself uses a Evaluate(”@UserRoles”). […]

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

    […] I needed to display for “regular” users information that was maintained database wide (preferable via a profile form). Although the usual “@Command( [EditProfileDocument] ; formname; uniqueKey )” worked fine for the db admin people to edit/maintain the information, there was no corresponding “OpenProfileDocument” or such. I wasn’t having much luck forcing a editmode profile document back into readmode for non admin people (using my IsInROle routine ), and I was about to go to a normal form and view when I figured out this way to open a Profile Document in non edit (read only) mode : […]

Leave a Reply


Close
  • Social Web
  • E-mail
E-mail It