Prblem with LS/Querymodechange

HiI’m really new in LS and so far a use trail and error to learn myself. But here i not have a clue to what i should do.

I use this in Querymodechange, but now they want to edit it if there is more then 12 hours left before the time they set in datefield “DateOK” and the field “OK” is not checked.

If OK is checked nothing should happend because when OK i checked the authors and readers field are correct. So the document should skip the Querymodechange in this case.

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)

' check that editor is member of selected uint

If Not source.EditMode Then

	Dim session As New notessession

	Dim ws As New NotesUIWorkspace

	Dim docUnit As notesdocument

	Dim view As notesview

	Dim db As NotesDatabase

	Dim item As NotesItem

	Dim doc As NotesDocument

	Dim result As Variant

	Dim hasRole As Variant

	

	Set doc = source.Document	

' check roles

	result = Evaluate(|@UserRoles|, doc)

	hasRole = False

	Forall n In result

		If n = "[Admin]" Or n= "[DatabaseConfig]" Then

			hasRole = True

			Messagebox "Your not allowed to edit this document." & unit$ , 0+16, "Error!"

			Continue = False

		End If

	End Forall

	

End If

End Sub

Kind regards

Leon

Subject: Problem with LS/Querymodechange

I’m not sure I understand what you’re trying to do in your current code. The way you have it, the user may NOT edit the document if they ARE in the [Admin] or [DatabaseConfig] roles. I would have expected that the user MAY edit the document if they are in those roles. I’m going to assume that’s what you meant.

Now you want to add the rule that anyone may edit the document if DateOK is > 12 hours in the future AND the OK field is not checked (i.e. OK = “”). You could write LotusScript code to test this, but it seems it might be easier to write a formula to test all these things at once:

@UserRoles *= (“[Admin]” : “[DatabaseConfig]”) | (@Adjust(DateOK; 0; 0; 0; -12; 0; 0; 0) > @Now & OK = “”)

Maybe I haven’t understood you correctly, but you could change the formula to suit yourself.

To use this formula in LotusScript, you could write a function like this:

Function EditOK(Source As Notesuidocument) As Boolean

Dim result

result = Evaluate( {above formula goes here }, Source.Document)

EditOK = result(0)

if Not EditOK Then

	Messagebox "You fool! You can't edit this document!"

End If

End Function

Now, in the Querymodechange event, you could do something like:

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)

' check that editor is member of selected uint

If Not source.EditMode Then

	Continue = EditOK(Source)

End If

End Sub

And don’t forget, you have to also call EditOK in Queryopen, if it is being opened in edit mode and is not a new document, so that the user can’t skip your test using Ctrl+E from a view.

Also, I want to caution you that LotusScript event code is not a security feature. If the user technically has access to edit the document, it’s not hard for them to change fields in spite of any event code you might add. They only need to know a little about Notes programming, for instance to create a toolbar button with a formula such as FIELD Status := “Approved”. If you want to be really certain of preventing unauthorized edits, you have to use an Authors field.

Subject: RE: Problem with LS/Querymodechange

Thank you for all your help, now a could continue with my learning.

Regards

Leon