UserRole Issue

Hi

I have a form that has user roles assigned to it - [Buyer] and [Finance]. The roles are assigned to groups of people. Staff with the [Finance] role create the form and then it goes to someone with the [Buyer] role to complete. There are fields on the form that are mandatory for people with the [Buyer] role to fill in, but no-one else needs to fill in these fields.

On the forms ‘OnSubmit’ property I have written the following code to check the user’s role and if the user has the [Buyer] role, they need to fill in certain fields. When I test the form, all users are being prompted to fill in the fields.

What have I done wrong?


Sub Onsubmit(Source As Notesuidocument, _

Continue As Variant)

Const s1$ = "@ismember(""[Buyer]"";@userroles)" 

Const s2$ = "@ismember(""[Finance]"";@userroles)" 

Dim doc As notesdocument 

Set doc = source.document 

Buyer = Evaluate(s1) 

Finance = Evaluate(s2) 





If Buyer(0) Then 

	If Source.FieldGetText("QueryType_1") = "" Then

		Messagebox "You must select a Query Type.",, "Top Query Error:"

		Call Source.GotoField("QueryType_1")

		Continue = False

	End If

	

	If Source.FieldGetText("Action_2") = "" And ((Source.FieldGetText("Us_Media_2") <> "") Or (Source.FieldGetText("M_Media_2") <> ""))Then

		Messagebox "You must select an Action.",, "Bottom Query Error:"

		Call Source.GotoField("Action_2")

		Continue = False

	End If

	

	If Source.FieldGetText("QueryType_2") = "" And ((Source.FieldGetText("Us_Media_2") <> "") Or (Source.FieldGetText("M_Media_2") <> ""))Then

		Messagebox "You must select a Query Type.",, "Bottom Query Error:"

		Call Source.GotoField("QueryType_2")

		Continue = False

	End If

	

	

	

End If

End Sub


Subject: UserRole Issue

QuerySave event is executed when the document is saved on the notes client and not onsubmit event.

Secondly add Exit Sub after every continue = false statement to stop further processing.

As you mentioned that the validations happen for every user, have you assigned the Buyer role to the default access ?

cheers!!

Ashish

Subject: UserRole Issue

Dear Sarah

You are fine using the onSubmit for this code - QuerySave used to be the sub that was used but Lotus would like to ‘encourage’ us to us onSubmit from now on instead.

I assume since you said that users were being prompted that you’re getting this issue on a server-based database, so its not the lack of the ‘enforce consistent ACL’ switch that is the problem.

Try this as a slightly different technique of using evaluate to examine the user’s roles:

Sub Onsubmit(Source As Notesuidocument, _

Continue As Variant)

Const s1$ = “@ismember(”“[Buyer]”“;@userroles)”

Const s2$ = “@ismember(”“[Finance]”“;@userroles)”

Dim doc As notesdocument

Dim varRoles as Variant, varIndex as Variant

Set doc = source.document

Buyer = Evaluate(s1)

Finance = Evaluate(s2)

varRoles=Evaluate(“@userroles”)

varIndex=ArrayGetIndex(varRoles,“[Buyer]”)

If not(isNull(varIndex)) Then 'The user had the role [Buyer]

If Source.FieldGetText(“QueryType_1”) = “” Then

Messagebox “You must select a Query Type.”, “Top Query Error:”

Call Source.GotoField(“QueryType_1”)

Continue = False

Exit sub

End If

If Source.FieldGetText(“Action_2”) = “” And ((Source.FieldGetText(“Us_Media_2”) <> “”) Or (Source.FieldGetText(“M_Media_2”) <> “”))Then

Messagebox “You must select an Action.”, “Bottom Query Error:”

Call Source.GotoField(“Action_2”)

Continue = False

Exit sub

End If

If Source.FieldGetText(“QueryType_2”) = “” And ((Source.FieldGetText(“Us_Media_2”) <> “”) Or (Source.FieldGetText(“M_Media_2”) <> “”))Then

Messagebox “You must select a Query Type.”, “Bottom Query Error:”

Call Source.GotoField(“QueryType_2”)

Continue = False

Exit sub

End If

End If

End Sub

Subject: RE: UserRole Issue

Sarah, you could also use the following function to test for roles:

Function HasRole (Role As String) As Integer

allroles = Evaluate(“@UserRoles”)

'Get the roles for the user and if user has the particular role

FoundRole% = False

Forall r In allroles

If r = Role Then

FoundRole% = True

End If

End Forall

HasRole = FoundRole%

End Function

Usage:

If HasRole(“[Approver]”) then

do something

else

do something else

end if

or

If not HasRole(“[Administrator]”) then

do something

end if