Here's a basic daily purge agent
By Jeffery A Lay 1 decade ago
Here's a simple LotusScript agent to zap expired documents daily. I haven't bugtested it extensively, but as a basic dumb daily purge it should be fine. Don't forget to comment out the actual deletion line while testing thoroughly if you decide to use this, or if you've changed selection criteria, or data loss could result. Printed progress updates are written to the standard output (Notes status line, or server log).
It could be a lot smarter if needed, but it's a start. Use as you see fit.
Agent: "Purge expired files"
Created Jul 5, 2010 by Jeff Lay/mcs/UK
Description: Basic unsmart deletion. Goes through file attachment documents and deletes any
which have an expiry date before today (but not today!)
Run this on a daily schedule at one minute past midnight for automated cleanup.
Dim nsSession As New NotesSession
Dim ndbDatabase As NotesDatabase
Set ndbDatabase = nsSession.CurrentDatabase
' Create a collection of file attachment documents with expiry dates before today's date
Dim ndcExpiredFiles As NotesDocumentCollection
Set ndcExpiredFiles = ndbDatabase.Search("@Date(file_ExpiryDate) < @Date(@Now)", Nothing, 0)
' Loop through the collection
Dim ndDocument As NotesDocument, ndDocToDelete As NotesDocument
Dim intDocCount As Integer
intDocCount = 0
Print "FileSender: Purging expired documents."
Set ndDocument = ndcExpiredFiles.Getfirstdocument()
While Not (ndDocument Is Nothing) ' If there are documents, perform the following steps
' Do it this way, because you can't select the next doc (which is based on the current doc)
' if the current doc has just been deleted.
intDocCount = intDocCount + 1
Set ndDocToDelete = ndDocument ' Prepare to delete the document
Set ndDocument = ndcExpiredFiles.Getnextdocument(ndDocument) ' Prepare the next step in the loop
Print "Purging expired doc with subject '" + CStr(ndDocToDelete.GetItemValue("file_Subject")(0)) + "', from " + CStr(ndDocToDelete.GetItemValue("file_Sender")(0)) + "."
ndDocToDelete.Remove(False) ' Delete the prepared document
Wend ' When there are no documents remaining to delete, exit the loop.
Print "Purged " + CStr(intDocCount) + " expired documents."