API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Collection Of Modified Documents
There may be a time when you'll need to collect all the documents which have been "recently" modified. For example, let's say you have a demo and want users to be able to create/edit documents, but then you want to automatically delete or reset the documents overnight.

"This is simple" you say.... just pick all the documents which have been created or modified in the last 24 hours.

But this can cause a problem. If your daily agent runs every 23 hours, 59 minutes, then some documents will be processing every day. Or if your agent didn't run one night for some reason (agent manager was hung, server was down, etc.) then there could be documents from a couple days ago that will never get processed.

So we came up with a little "script-let" that grabs a collection of documents which have been created or modified since the last time the agent ran. It's commented, so it's pretty self-explanatory.

Here is the code....

Sub Initialize
   Dim s As New notessession
   Dim db As notesdatabase
   Set db = s.currentdatabase
   Dim thisagent As notesagent
   Set thisagent = s.currentagent
   Dim datetime As New notesdatetime(Cstr(thisagent.lastrun))
   ' Note - the first time this agent runs (or if the agent is
   ' ever modified) there really isn't a "lastrun" property,
   ' but Notes is nice and returns a value for "lastrun" of
   ' 12/30/1899, so the first time this agent will give you
   ' all the documents in the database, which is probably what
   ' you want.
   Dim coll As notesdocumentcollection
   ' There are 3 parms for the search. The first is the search
   ' formula, the second is the cutoff date, and the third is
   ' the maximum number of documents. Since we want all documents
   ' created or modified after the cutoff date, use "@All" as
   ' the search formula and 0 as the maximum (meaning return all).
   Set coll = db.search("@All", datetime, 0)
   ' Now process all the documents in the collection
   Dim i As Integer
   Dim doc As notesdocument
   Set doc = coll.getfirstdocument()
   While Not(doc Is Nothing)
      ' ........ do your processing here ...........
      Set doc = coll.getnextdocument(doc)
   Wend
End Sub