Hello,
I’m having a problem with the agent to write to the document in other database(A_db) from the current database, and copy the current document to A_db. The agent is triggered in the postsave event in the form. The current document has “Title” field(text) and “RevNum” field(number). The key for GetDocumentByKey is
doc.Title(0) & “-” & CStr(doc.RevNum(0) - 1)
The A_db has the document with the same title as the current database, and RevNum that has one less number than the document in current database. In fact, this agent works most of the time. However, it doesn’t work only for the certain documents. When the agent works, it writes “1” to “MoveToArchive” field in the selected document to remove the document from the MainView, then copy the current document to db_A. For these problematic documents, seems like it writes “1” to both the selected document, and the document that is just copied to db_A. Therefore, both documents are removed from “MainView”…
Theoretically, GetDocumentByKey would grab only one document, so I don’t understand why it grabs two documents. It doesn’t error out either. Here is the code. I would appreciate if anyone can help me. Thank you very much in advance.
Dim w As NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim A_db As New NotesDatabase( “”, “” )
Call A_db.Open( “ServerA”, “DatabaseA.nsf” )
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Set w = New NotesUIWorkspace
Set db = session.CurrentDatabase
Set uidoc = w.CurrentDocument
Set doc = uidoc.document
If Not (doc Is Nothing) Then
'Write 1 to MoveToArchive field in to be deleted doc
Dim view As NotesView
Dim key As String
Dim ToBeDelDoc As NotesDocument
If doc.RevNum(0) > 0 Then
key = doc.Title(0) & “-” & CStr(doc.RevNum(0) - 1)
Set view = A_db.GetView( “MainView” ) '1st column is Title-RevNum, categorized
Call view.Refresh
Set ToBeDelDoc = view.GetDocumentByKey(key , True )
If Not(ToBeDelDoc Is Nothing) Then
ToBeDelDoc.MoveToArchive = “1”
Call ToBeDelDoc.Save(False, False)
End If
End If
'copy document to A_db
Call doc.CopyToDatabase( A_db )
End If