I wrote an agent to purge old documents. Slightly cheesey since it uses the "Events\By Date" view. I should at least have added an alias to the view, but I wanted to change as few elements as possible to preserve my ability to upgrade to later releases.
Scheduled to run on the first of the month. Uses a DbProfile profile document. If one doesn't exist, it creates one. I didn't bother making the functionality to actually edit the profile document yet.
Sub Initialize
Dim db As NotesDatabase<br/>
Dim doc As NotesDocument ' from view<br/>
Dim docNext As NotesDocument ' view.GetNextDocument(doc)<br/>
Dim docProfile As NotesDocument ' db.GetProfileDocument("DbProfile")<br/>
Dim dtPurge As Variant ' @Adjust(today, 0; -iPurgeMonths; 0; 0; 0; 0)<br/>
Dim iPurgeMonths As Integer ' number of months to leave in db<br/>
Dim iRemoved As Long ' number of documents removed by this agent<br/>
Dim itemPurgeMonths As NotesItem ' the PurgeMonths field on docProfile<br/>
Dim ndt As NotesDateTime ' today - iPurgeMonths<br/>
Dim sngKey As Single ' YYYY.MM number correlating to dtPurge, used to match against similar values within view<br/>
Dim view As NotesView ' Events\By Date view<br/>
Dim session As New NotesSession<br/>
<br/>
On Error Goto ErrorSub<br/>
<br/>
Set db = session.CurrentDatabase<br/>
Set docProfile = db.GetProfileDocument("DbProfile")<br/>
Set itemPurgeMonths = docProfile.GetFirstItem("PurgeMonths")<br/>
If itemPurgeMonths Is Nothing Then<br/>
iPurgeMonths = 3<br/>
With docProfile<br/>
.PurgeMonths = 3<br/>
.Form = "DbProfile"<br/>
.Save True, True<br/>
End With<br/>
Else<br/>
iPurgeMonths = itemPurgeMonths.Values(0)<br/>
End If<br/>
<br/>
Set ndt = New NotesDateTime("Today")<br/>
Call ndt.AdjustMonth(0 - iPurgeMonths)<br/>
<br/>
dtPurge = ndt.LocalTime<br/>
sngKey = Year(dtPurge) + (Month(dtPurge) - iPurgeMonths) * 0.01<br/>
Set view = db.GetView("Events\by Date")<br/>
Set doc = view.GetFirstDocument<br/>
Do Until doc Is Nothing<br/>
If doc.ColumnValues(0) > sngKey Then Exit Do<br/>
Set docNext = view.GetNextDocument(doc)<br/>
Call doc.Remove(False)<br/>
Loop<br/>
Set ndt = New NotesDateTime("Today")<br/>
Call ndt.AdjustMonth(0 - iPurgeMonths)<br/>
<br/>
dtPurge = ndt.LocalTime<br/>
sngKey = Year(dtPurge) + (Month(dtPurge) - iPurgeMonths) * 0.01<br/>
Set view = db.GetView("Events\by Date")<br/>
Set doc = view.GetFirstDocument<br/>
Do Until doc Is Nothing<br/>
If doc.ColumnValues(0) > sngKey Then Exit Do<br/>
Set docNext = view.GetNextDocument(doc)<br/>
Call doc.Remove(False)<br/>
iRemoved = iRemoved + 1<br/>
Set doc = docNext<br/>
Loop<br/>
ExitSub:
If iRemoved Then Call LogEvent("Removed " & iRemoved & " old documents.", SEVERITY_LOW, Nothing)<br/>
Exit Sub<br/>
ErrorSub:
Call LogError()<br/>
On Error Resume Next<br/>
Resume ExitSub<br/>
End Sub