Yesterday I got a mail from one of the Notes developer from Notes Forum with below contents :

We recently upgraded our Notes environment from R5 to R7 and currently running to an issue with one of my workflow database. I have an 'Author' field which capture names, date and time when users approve/validate a request. This field stop working since when users validate requests with R7 Client.. If users approve a request with R5 Client, their names appear in the field.


I'm using the following code in the Terminate Event of the "Author" field. When users approve a requests, the approver name, date and time supposed to be appended to this field but it's blank now. Can you please help me modifying the code?


Sub Terminate
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument

Author = uidoc.FieldGetText ("Author")
RevApproval_a = uidoc.FieldGetText ("RevApproval")

If Author = "" Then
If RevApproval_a <> "" Then
Author = "Completed by " & session.CommonUserName & " on " & Format(Now(), "Long Date")
Call uidoc.FieldSetText ("Author", Author)
Call uidoc.save
End If
End If
End Sub


I don't have R5 client So, I was not able to test the code.But tested in R7 and it was not working (Can't check in debugger also because it doesn't work in Terminate event).When I analyze the code , I don't find anything wrong with that.In jiffy I modified the code and send back to that person , Since it was urgent request.My code was -

Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Dim doc As NotesDocument

uidoc.EditMode=True
Set doc=uidoc.Document

If doc.GetItemValue("Author")(0) = "" Then
If doc.GetItemValue("RevApproval")(0) <> "" Then
Call doc.ReplaceItemValue("Author","Completed by " & session.CommonUserName & " on " & Format(Now(), "Long Date"))
Call doc.Save(True,False)
End If
End If

After replying him, I thought to analyze the code and something has instantly strikes in my mind "Will NotesUIdocument works in terminate event?" I have tested his old code in some other event and it worked as he expected.It was very small thing , But skipped from my mind :(

Further more I thought to dig something more about Notes events, I found something useful for those who always skips small things , like me :)

* You not use Initialize for anything except agents, and not use Terminate at all

* Each object has a Declarations area where you can write non-executable statements that apply to all events in the object, and an Options area for statements such as Option, Use, UseLSX, and Const. Each document and view has a Globals area where you can write non-executable statements that apply to all objects in the document.

* Changes made to the current document in a PostOpen event are treated as default values. The document is not marked as changed. If the user closes the document at this point, the PostOpen changes are lost. You must explicitly save the changes, for example, with the Save method of NotesUIDocument, if you want to be sure they are applied.

But still a question, how to debug your code which is in "Terminate" event ?
I think only way "MSGBOX" :) , Anything else you guys know ?

1 Response to "Terminate Event and NotesUIDocument"

  1. gravatar Vinay Kumar Gowda Says:

    I did faced this problem when our application started giving problems. When document link is oepned from notes client - we had bit of a code in Initialise event to open the document in browser or notes client depending on the userroles. The code was in use for many years and started giving broken links for browser users when uidoc.currentdocument is used in Initialise event. Lotus notes was assuming the current document is the email from where document link is being clicked.

Leave a Reply

preload preload preload