Error in my LS code in the QuerymodeChange

Hello,

I am very new to LS, and I am facing a problem that I cannot solve. In the QueryModeChange I have this simple code:

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim uidoc As NotesUIDocument

Dim acl As NotesACL    

Dim entry As NotesACLEntry

Set db = session.CurrentDatabase

Set acl = db.ACL

Set entry = acl.GetEntry( session.CommonUserName )



If entry Is Nothing Then

	Set entry = acl.GetEntry( session.UserName )

End If



If entry.IsRoleEnabled( "[utilisateur]" ) Then

	If Source.FieldGetText("stt") = "Approbation" Then

		Messagebox "Cette demande a été soumise pour approbation, elle ne peut plus être modifié"

		continue = False

	End If

End If

End Sub

This code make sure that a user cannot modify the form on a certain conditions.

I’m getting this error: “Object variable not set” if I do not have the role “utilisateur”.

I do not have this error if I have the role “utilisateur”.

Thanks for your help

Subject: Error in my LS code in the QuerymodeChange

Hi

1st)

Syntax

flag = notesACLEntry.IsRoleEnabled( name$ )

Parameter

name$

String. The name of the role. The recommended style is to use just the name, with no parentheses or square brackets around it. If square brackets surround the name, they will be stripped and the enclosed name used.

So remove the brackets first.

2nd)

The error may be somewhere else, if you tried it with an already approved doc (you did not tell about the value of ‘stt’…!)

Continue your tests with an ‘else’ section after your ‘continue=false’ line, displaying a message box…

HTH

ian

Subject: Error in my LS code in the QuerymodeChange

Could it be that Entry is nothing?Are you individually in the ACL?

Subject: Error in my LS code in the QuerymodeChange

It seems to me that the ‘entry’ variable is not getting set.

This would mean that the line entry.isRoleEnabled would give you an ‘Object variable not set’ error.

Have you tried stepping through the code in the debugger?

Frunobulax.

Subject: Error in my LS code in the QuerymodeChange

Hi,

For checking UserRoles I prefer Evaluate:

Sub sQuerymodechange(Source As Notesuidocument, Continue As Variant)

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim vUserRoles As Variant

Dim isUtilisateur As Boolean



isUtilisateur = False

vUserRoles = Evaluate ( "@UserRoles", source.Document )

If Isarray( vUserRoles ) Then

	Forall role In vUserRoles

		If role = "[utilisateur]" Then isUtilisateur = True

	End Forall

End If

If  isUtilisateur Then

	If Source.FieldGetText("stt") = "Approbation" Then

		Messagebox "Cette demande a été soumise pour approbation, elle ne peut plus être modifié"

		continue = False

	End If

End If

End Sub

If it doesnt work for you, please post on which Line you get the “Object variable not set” Error.

Greetings,

Martin

Subject: RE: Error in my LS code in the QuerymodeChange

Working fine, thank’s for your help!

Subject: Single Person or Group Member in ACL?

Hi,

your method has a disadvantage:

If you are not by your name in the ACL, but as a groupmember, and the role is granted to the group, you have no chance of recognizing you have the rule.

@UserRoles always calculates that, so Evaluating it is a good shortcut.

Greeting

Martin

Subject: RE: Single Person or Group Member in ACL?

Something like this:

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