Archiving - CopyToDatabase method with child documents

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

This was first published in September 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.