Use Approve Button in Read & Edit Mode

I have a button that allows users to approve the document. I’d like the users to be able to use the button in either read or edit mode (although I think it’ll be used in read mode most of the time). Below is the code that I have in the button and it works fine in edit mode but not in read mode.

The “Call ApproveDoc(doc)” line of code is a subroutine that adds the current user to the “CurrentApprovers” group, sets the Status field to “Approved”, and adds a line to the “ApprovalHistory” field. This subroutine is also used in the QuerySave event so if the user is in the Approvers group, the document is automatically approved.

Does anyone have any suggestions?

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim uiDoc As NotesUIDocument

Dim doc As NotesDocument

Dim answer As Variant, hasNotApproved As Variant

Set db = session.CurrentDatabase

Set uiDoc = workspace.CurrentDocument

Set doc = uiDoc.Document

hasNotApproved = Evaluate(|!@IsMember(@Name([CN]; @UserName); CurrentApprovers)|, curDoc)

If hasNotApproved(0) Then

answer = workspace.Prompt(PROMPT_YESNO, “Confirmation”, “Are you sure that you want to approve this document?”)

If answer = 1 Then

Call ApproveDoc(doc)

Call doc.Save(True, False)

Else 'if answer is No, then exit

Exit Sub

End If

Else

Msgbox “You’ve already approved this document.”, 0 + 16, “Already Approved”

Exit Sub

End If

Subject: Use Approve Button in Read & Edit Mode

It is interesting that your evaluate statement is using ‘curDoc’, and ‘curDoc’ is not ever set. I would think you should have ‘doc’ for the referenced document.Also, why not put the document in edit mode if it is not already…

If Not (uidoc.EditMode) then

uidoc.EditMode = True

End if

Subject: Use Approve Button in Read & Edit Mode

u could do this in formula to the code will be faster

However add an if statement to check if uiview is open and then use the session.unprocesseddocuments method to get the selected document and process it.