I’m trying to figure out what a developer has done. This code is in an agent in a database. What does it do?
Sub initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dateTime As New NotesDateTime ("1/1/2002")
Dim collection As NotesDocumentCollection
Dim Date1 As Variant
Dim Date2 As Variant
Dim Today1 As New NotesDateTime("Today")
Dim m As Integer
Dim DateM As Variant
Dim dateY As Variant
Dim d As Integer
Dim ty As Integer
y = Year(Today1.LSLocalTime)
m = Month(Today1.LSLocalTime)
If m = 1 Then
dateM = 12
dateY = y-1
Else
dateM = m-1
dateY = y
End If
d = Day(Today1.LSLocalTime)
Select Case dateM
Case 1, 3, 5, 7, 8, 10, 12
d = 31
Case 2
d = 28
Case Else
d = 30
End Select
'build date values for search
Date1 = dateM & "/1/" & dateY
Date2 = dateM & "/" & d & "/" & dateY
'build search string for collection that is docs with due date in prior month
searchFormula$ = "(FIELD Due >= " & Date1 & " & FIELD Due <= " & Date2 &")"
Set db = session.CurrentDatabase
Set collection = db.FTSearch (searchFormula$,0)
For i = 1 To collection.Count
Set doc = collection.GetNthDocument(i)
Dim docB As NotesDocument
Set db = session.CurrentDatabase
Set docB = New NotesDocument (db)
Call doc.CopyAllItems (docB, True)
docB.status = "New"
docB.createdBy = session.CommonUserName
docB.date = Today()
docB.file_date = Null
docB.contact = Null
docB.filed = "No"
'get year value from due field
Dim itemB As NotesItem
Dim datetimeB As NotesDateTime
Set itemB = docB.getfirstitem ("due")
Set datetimeB = itemB.datetimevalue
Call datetimeB.adjustyear (1)
Set docB.due = datetimeB
'get year value from ActualDate field if there is a value
Set itemB = docB.getfirstitem ("ActualDate")
If Not Isempty (item) Then
Set datetimeB = itemB.datetimevalue
Call datetimeB.adjustyear (1)
Set docB.ActualDate = datetimeB
End If
'Save DocB
Call docB.Save (True,True)
Next
End Sub