Roles, Contain with Lotusscript

Good Day,

Is there not a Lotus method to complete an @contains method on database Roles??

other than pulling the roles, assigning them to a string and then completing an instr I haven’t found a solution that works.

I have tried Evaluate(|@Contains(tmpstring; “PowerUser”)|)

and I get back a result of 0 despite the fact that tmpstring is hardcoded as tmpstring = “PowerUser” .

Does anyone have a better solution for checking a current users roles via lotusscript.

I should mention that this script is being launched off a navigator so there isn’t a doc to read from… Unless I go about create another doc in the background with a form with @userroles and do an @ contians for the fields???

I don’t know…

Subject: Roles, Contain with Lotusscript

On my way out, so no time to break down the code, but here is a script I use to check whether a person can create a comment based on a role and some other criteria.

Sub Click(Source As Button)

Dim wk As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As notesdocument

Dim pdoc As notesdocument

Dim session As New NotesSession

Dim db As NotesDatabase

Dim acl As NotesACL

Dim entry As NotesACLEntry

Dim entry2 As NotesACLEntry 'The matching entry is set to this

Dim dateTime As New NotesDateTime( "" )

Dim body As Variant

Dim cloop As Boolean

Dim editor As notesitem

'Dim rtitem As NotesRichTextItem

'Dim attach As NotesEmbeddedObject



Dim rname(1 To 5) As String

Dim pr As String

Dim rtfpr As String

Dim x As Integer

Dim y As Integer

Dim al As Integer 'length of the current user's role

Dim almod As Integer 'al - 2 which is used to remove the brackets from the role

Dim a As String 'current user's role without brackets

Dim uname As String 'current user's name

Dim roleswhocanedit As Variant 'stores roles of those who can edit any comments

Dim canedit As Boolean 'set if the user's role is one that can edit any comments

Dim tdata As String 

Dim groupmembers As Variant 	'explode the group members in the ACL and use those when comparing to the current user.

Dim pstrGroupName As String	'Group name in the acl

Dim pvarGroupMembersOut As Variant	'Members of the group in the acl

Dim activerole As String

Static tempvar As String 'this is the variable that will be used, that way it stays the same throughout the loop



Set db = session.CurrentDatabase

Set acl = db.ACL

Set uidoc = wk.CurrentDocument

Set doc = uidoc.Document



Set pdoc = db.GetProfileDocument("settings")

roleswhocanedit = doc.cpEditRoles



uname = session.CommonUserName

Set entry = acl.GetFirstEntry



While Not (entry Is Nothing)

	If entry.IsGroup Then

		pstrGroupName = entry.Name

		groupmembers = expandGroupNames(pstrGroupName)

			'Check to see if the groupmembers list contains the current user.  if so, exit the wend, else loop

		Forall gdata In groupmembers

			If gdata = session.UserName Then

				Set entry2 = entry

			End If

		End Forall

	Else

		If Lcase(entry.Name) = Lcase(session.UserName) Then

			Set entry2 = entry

		End If

	End If

	Set entry = acl.GetNextEntry(entry)

Wend



If entry2 Is Nothing Then

	Exit Sub

End If

x = 1	



cloop = False

Forall r In entry2.Roles

’ Messagebox( r )

	rname(x) = r

	Forall data In roleswhocanedit

		If (Not cloop = True) Then

			If (Not data = "") Then

				tdata = "[" + data + "]"

’ Msgbox rname(x) + "Show all role values that are in the edit list: " + tdata

				If rname(x) = tdata Then

					canedit = True

					tempvar = data

					cloop = True

’ Msgbox TEMPVAR + " " + rname(x) + " " + tdata

					Print TEMPVAR + " " + rname(x) + " " + tdata

				End If

			End If

		End If

	End Forall

	x = x + 1

End Forall



al = Len(rname(1))

activerole = Mid$(rname(1), 2, al - 2)

’ Msgbox TEMPVAR

Print tempvar

If doc.wrpcxAuthor_1(0) = uname Or doc.wrpcxAuthor_1(0) = "" Or canedit Then

	'Msgbox "good to go"

Else

	Msgbox uname + Chr$(10) + "Only " + doc.wrpcxAuthor_1(0) + " or an administrator may edit this comment."

	Exit Sub

End If



'After the correct role is found and the code runs, will drop out so no extra loops are invoked.

If tempvar = doc.wrpcxrole_1(0) Or "" = doc.wrpcxrole_1(0) Or  canedit Then

	'Throw up a prompt for Comments and fill out wrpcxComments_1

	With doc

’ pr$ = Inputbox(“Enter your comment here…”, “Comments”, doc.wrpcxcomments_1(0))

		.txtcomment = .wrpcxcomments_1

		pr$ = wk.DialogBox("dlgComment", True, True, False, False, False, False, "Comment", , False, False, True)

		

		If pr$ <> False Then

			.wrpcxComments_1 = .txtcomment

			'May want to only update this the first time.. ie if it is blank.  

			If .wrpcxrole_1(0) = "" Then

				.wrpcxrole_1 = activerole 'use this because tempvar is only those people in roleswhocanedit

			End If

			'Current Date and Time only for new rows

			If .wrpcxAuthor_1(0) = "" Then

				dateTime.LSLocalTime = Now

				.wrpcxCreateTime_1 = dateTime.DateOnly & Chr(10) & dateTime.TimeOnly

			End If

			'only update the author name if it is currently blank, else, leave it alone

			If .wrpcxAuthor_1(0) = "" Then

				.wrpcxAuthor_1 = session.CommonUserName

			End If

			'Append the editor's name to the field

			Set editor = doc.GetFirstItem( "wrpcxEditor_1" )

			Call editor.AppendToTextList( session.CommonUserName & " (" & activerole & ") - " & Cstr(Now) )

		End If

	End With	

End If



'empty the comment field on this form.

doc.txtcomment = ""



Call uidoc.Refresh(False)	

Set session = Nothing

Set wk = Nothing

errhndl:

End Sub

Subject: Roles, Contain with Lotusscript

Use QueryAccessRoles:

If Instr(Join(db.queryaccessroles(session.username), " "), “[RoleName]”)>0 then

''the user has the role

Also, in formula us @ismember, as @userroles returns a text list not a string (just slightly easier imo):

@if(@ismember(“[RoleName]”;@userroles))

This formula can be evaluated also, but is probably slightly slower.

hth

dan

Subject: Roles, Contain with Lotusscript

I posted a Lotusscript function to do exactly what you want here:

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/f7ec9d5e9dedaa898525722c004f78c6?OpenDocument

Frunobulax

Subject: RE: Roles, Contain with Lotusscript

If you don’t like iterating thru a Forall loop, Luke Kolin posted this nice alternative a few years ago: http://www-10.lotus.com/ldd/nd6forum.nsf/0/36e5b3dd03a26a5185256ce10053fa36

Subject: Nice one!

Subject: RE: Roles, Contain with Lotusscript

That is very similar to what I was just trying before checking back on the board…

Works like a charm… Thanks for the feedback…