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:
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.
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! ]
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…]
Pingback: False Positives » Using LotusScript Evaluate to save lots and lots of work
Pingback: False Positives » Blog Archive » Opening a Lotus Notes Profile Document in Read Only mode