Insert the code. In the Programmers pane, change the Language Selector from Simple action(s) to LotusScript and add the following LotusScript in the Initialize section. Be sure to replace VIEW, SERVER, and DATABASE with valid values.
Sub Initialize
-----------------------------------------------------
Define the objects
-----------------------------------------------------
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dbArchive As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim tmpDoc As NotesDocument
Dim docArchive As NotesDocument
Dim archiveDate As NotesDateTime
Dim createDate As NotesDateTime
Dim count As Integer
Dim serverName As String
Dim archiveName As String
Set db = s.CurrentDatabase
-----------------------------------------------------
Set Cutoff date. This should be a negative number.
For example, set to -90 to archive documents that
are over 3 months old based on the creation date.
-----------------------------------------------------
Set archiveDate = New NotesDateTime( "Today" )
Call archiveDate.AdjustDay( -90 )
-----------------------------------------------------
Specify the view that contains documents that
might be archived.
-----------------------------------------------------
Set view = db.GetView("VIEW")
view.AutoUpdate = False
-----------------------------------------------------
Specify the server and database name to be
used to store the archived documents.
-----------------------------------------------------
serverName = "SERVER"
archiveName = "DATABASE.NSF"
Set dbArchive = New NotesDatabase( serverName, archiveName )
-----------------------------------------------------
Begin processing
-----------------------------------------------------
If dbArchive Is Nothing Then
Print "Warning: unable to access archive database."
Else
-------------------------------------------------
Start archive process
-------------------------------------------------
count = 0
Set doc = view.GetFirstDocument
While Not(doc Is Nothing)
Set tmpDoc = view.GetNextDocument( doc )
Set createDate = New NotesDateTime( "" )
createDate.LocalTime = doc.Created
If archiveDate.TimeDifference( createDate ) > 0 Then
Set docArchive = New NotesDocument( dbArchive )
Call doc.CopyAllItems( docArchive, True )
Call docArchive.Save( True, True )
Call doc.Remove( True )
count = count + 1
End If
Set doc = tmpDoc
Wend
Print "Complete: "+Cstr( count )+" document(s) archived."
End If
End Sub
Note
The archive cutoff date must be set to a negative number. In this example, the value is set to 90, which equates to three months. Increase the number of days to retain documents for a longer duration or decrease the number to retain them for a shorter period.
Tip
To test the agent, comment out the statement Call doc.Remove(True) by prefixing this statement with a single quote or the word REM. This will keep the documents in the originating database. When you are sure the agent is working as intended, uncomment the statement, and documents will be copied to the new database and removed from the original database. Using this approach will prevent documents from being deleted in the primary database but will create documents in the archive database. After the agent has been tested and verified to be working as designed, remember to uncomment the statement.
|