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 Show-n-Tell+Thursday. 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- Using LotusScript Evaluate to save lots and lots of work
- Very simple LotusScript function to parse value on url line
- Using Lotus Notes ACL Roles rather than Groups Names in our ACL
- Opening a Lotus Notes Profile Document in Read Only mode
- Getting around Lotus Notes Domino (Web) Error 4354: Cannot remove NotesDocument when it is the Document Context


March 10th, 2006 at
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! ]
March 30th, 2006 at
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…]
June 22nd, 2006 at
[…] 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”). […]
October 25th, 2006 at
[…] 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 : […]