Many Lotus Notes applications require some sort of archiving feature to manage the size of the production application and to increase performance. In an application that has documents with parent-child relationships, archiving can be tricky. If you archive a parent document you have to ensure that all of the child documents are archived as well so no orphans are created. Maintaining the parent-child relationship even after copying is fairly easy to do using the DocumentCollection class and the CopyToDatabase method in LotusScript. The code below archives selected documents in a view using the UnprocessedDocuments Property in the NotesDatabase class. Use this code in an agent and create a button in a view to actuate it.
Note: this agent returns only immediate responses to a document, and does not include responses-to-responses. But, the code could be modified to check each response for the existence of response-to-responses as well.
When should this agent run?
Manually from Actions Menu
Which document(s) should it act on?
What should this agent run?
(Declarations) Dim ns As NotesSession Dim ndb As NotesDatabase Dim ArchiveDb as NotesDatabase Dim collection As NotesDocumentCollection Dim kidDocs as NotesDocumentCollection Dim kid as NotesDocument Dim parent As NotesDocument Dim switchDoc As NotesDocument Sub Initialize Set ns = New NotesSession Set ndb = ns.CurrentDatabase Set ArchiveDb = ns.GetDatabase('your code here') Set collection = ndb.UnprocessedDocuments Set parent = collection.GetFirstDocument If ArchiveDb.Title = "" Then Msgbox("Couldn't find the Archive Database. Please contact the Notes Admins.") ExitSub End If Do Until parent is Nothing Call parent.CopyToDatabase(ArchiveDb) Set kidDocs = parent.Responses Set kid = kidDocs.GetFirstDocument Do Until kid is Nothing Call kid.CopyToDatabase(ArchiveDb) Set switchDoc = kid Set kid = kidDocs.GetNextDocument(kid) Call switchDoc.Remove(True) Loop Set switchDoc = parent Set parent = collection.GetNextDocument(parent) Call switchDoc.Remove(True) Loop End Sub
This was first published in September 2001