Manage Learn to apply best practices and optimize your operations.

Archiving - CopyToDatabase method with child documents

Use this code in an agent and create a button in a view to actuate it.

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?
Selected documents

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

Dig Deeper on Domino Resources - Part 2

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...