OpenNTF.org - Archive documents with recursi
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Archive documents with recursive response documents (unlimited) 
Rating:
Rating: 1 , Number of votes: 1 
Contributor:
Andrew Jones 
Category:
Lotus Formula 
Type:
 
Last Modified:
17 Jun 2002 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Usage / Example
I saw the other gentleman's code to archive docs and their response docs. I was immediately prompted to post this. This code will archive a parent doc with all of it's response documents to another database. The response heirarchy (which may be multi-level) is maintained.

Example usage:
Dim NewParentUNID As String
NewParentUNID = ArchiveDocument (Doc, Nothing, TargetDatabase, "")

The first parameter is the parent NotesDocument for everything. Pass in the doc you want to archive.

The second parameter is only used internally by the function. Call it with the Nothing object. This is a NotesDocument for the parent of the document in the first parameter.

pThe third parameter is the target NotesDatabase.

The forth parameter is a running list of Universal IDs. I've seen databases that have broken response structures where a parent can be a child of one of it's children. This looks like Doc.Responses(0).Responses(0) = Doc. This just prevents the code from entering an infinite loop.



Code


Function ArchiveDocument(SourceDoc As NotesDocument, ParentDoc As NotesDocument, ArchiveDb As NotesDatabase, PrevUNIDs As String) As String
Dim TargetDoc As NotesDocument
Dim ResponseDoc As NotesDocument
Dim i As Integer
Dim NUL As Variant

If Instr(PrevUNIDs, SourceDoc.UniversalID) = 0 Then
PrevUNIDs = PrevUNIDS & "," & SourceDoc.UniversalID

Set TargetDoc = SourceDoc.CopyToDatabase(ArchiveDb)
TargetDoc.ArchiveDate = Now()
If Not (ParentDoc Is Nothing) Then
Call TargetDoc.MakeResponse(ParentDoc)
End If
Call TargetDoc.Save(True, True)
ArchiveDocument = Trim(Cstr(TargetDoc.UniversalID))

If SourceDoc.Responses.Count > 0 Then
For i = 1 To SourceDoc.Responses.Count
Set ResponseDoc = SourceDoc.Responses.GetNthDocument(i)
If Not ResponseDoc Is Nothing Then
NUL = ArchiveDocument(ResponseDoc, TargetDoc, ArchiveDb, PrevUNIDs)
End If
Next
End If
Call SourceDoc.Remove(True)
End If
End Function

 Comments
Posted by Joshua b Jore on 04/06/2004 02:48:37 PMPlagarism
I wrote this function a while back and likely posted it here under my own name. Andrew did not write this.
 Add your comment!