• Anonymous
  • Login
  • Register
OpenLog - Feature Request: Purge Old Documents Agent


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
Dim doc As NotesDocument ' from view
Dim docNext As NotesDocument ' view.GetNextDocument(doc)
Dim docProfile As NotesDocument ' db.GetProfileDocument("DbProfile")
Dim dtPurge As Variant ' @Adjust(today, 0; -iPurgeMonths; 0; 0; 0; 0)
Dim iPurgeMonths As Integer ' number of months to leave in db
Dim iRemoved As Long ' number of documents removed by this agent
Dim itemPurgeMonths As NotesItem ' the PurgeMonths field on docProfile
Dim ndt As NotesDateTime ' today - iPurgeMonths
Dim sngKey As Single ' YYYY.MM number correlating to dtPurge, used to match against similar values within view
Dim view As NotesView ' Events\By Date view
Dim session As New NotesSession

On Error Goto ErrorSub

Set db = session.CurrentDatabase
Set docProfile = db.GetProfileDocument("DbProfile")
Set itemPurgeMonths = docProfile.GetFirstItem("PurgeMonths")
If itemPurgeMonths Is Nothing Then
iPurgeMonths = 3
With docProfile
.PurgeMonths = 3
.Form = "DbProfile"
.Save True, True
End With
Else
iPurgeMonths = itemPurgeMonths.Values(0)
End If

Set ndt = New NotesDateTime("Today")
Call ndt.AdjustMonth(0 - iPurgeMonths)

dtPurge = ndt.LocalTime
sngKey = Year(dtPurge) + (Month(dtPurge) - iPurgeMonths) * 0.01
Set view = db.GetView("Events\by Date")
Set doc = view.GetFirstDocument
Do Until doc Is Nothing
If doc.ColumnValues(0) > sngKey Then Exit Do
Set docNext = view.GetNextDocument(doc)
Call doc.Remove(False)
Loop
Set ndt = New NotesDateTime("Today")
Call ndt.AdjustMonth(0 - iPurgeMonths)

dtPurge = ndt.LocalTime
sngKey = Year(dtPurge) + (Month(dtPurge) - iPurgeMonths) * 0.01
Set view = db.GetView("Events\by Date")
Set doc = view.GetFirstDocument
Do Until doc Is Nothing
If doc.ColumnValues(0) > sngKey Then Exit Do
Set docNext = view.GetNextDocument(doc)
Call doc.Remove(False)
iRemoved = iRemoved + 1
Set doc = docNext
Loop
ExitSub:
If iRemoved Then Call LogEvent("Removed " & iRemoved & " old documents.", SEVERITY_LOW, Nothing)
Exit Sub
ErrorSub:
Call LogError()
On Error Resume Next
Resume ExitSub
End Sub



Taken Actions by Owners

No actions have been taken yet.


Documents
In this field you can enter the actual request.

You can use the rich text editor for rich text formating. You can also enter HTML to embed objects, e.g. to embed a YouTube video or a screenshot of the project. In this case use '[' and ']' to mark the passthrough HTML as such.

Please note that the first time you use the new UI your description is converted from rich text to MIME. You might want to copy and paste the raw plain text from the old UI in the new UI so that you don't loose information.
In this field owners can describe what they have done or want to do.

You can use the rich text editor for rich text formating. You can also enter HTML to embed objects, e.g. to embed a YouTube video or a screenshot of the project. In this case use '[' and ']' to mark the passthrough HTML as such.

Please note that the first time you use the new UI your description is converted from rich text to MIME. You might want to copy and paste the raw plain text from the old UI in the new UI so that you don't loose information.