I am having trouble executing a scheduled agent. I have read all the FAQ's and can't find the answer

Hi there everyone,

I have written the following code in an agent. the Agent logs show that the agent executes. It also shows that the agent ran on xx documents. But, the code is not really executing. If it was, it would have actually activated the documents that met the criteria. If I run the agent manually, I have no problem.

I have a special account that all agents are signed by. I have verified that the signer of the Agent had not changed. I have also ensured that all recommendations made by Julie on the Agent FAQ were in place.

Can someone please look at this code and tell me if I am doing something wrong?

Sub Initialize

Dim mailfilename As Variant	

Dim delegate As Variant

Dim details1 As Variant

Dim details As String

Dim mailfilename1 As String

Dim usersname As Variant

Dim empname3 As String	

Dim departuredat As Variant

Dim deptdate2 As NotesDateTime

Dim todaysdate As New NotesDateTime(" ")

Dim todaysdate2 As New NotesDateTime(" ")

Dim yesterdaysdate As New NotesDateTime( " ")

Dim deptdate1 As NotesItem

Dim returndat As Variant

Dim retdate1 As NotesItem	

Dim bookbusytime1 As NotesItem

Dim GeneralSubject As String

Dim GeneralSubject1 As NotesItem

Dim DaysOut As String

Dim DaysOut_1 As NotesItem

Dim DaysOut1 As NotesItem

Dim datefirstdayback As NotesItem

Dim datefirstdayout As NotesItem

Dim GeneralMessage As String

Dim GeneralMessage1 As Variant

Dim subject1 As NotesItem

Dim outofofficeprofile As Variant

Dim doc As NotesDocument

Dim session As New NotesSession

Dim db As NotesDatabase

Dim agent As NotesAgent

Dim db3 As NotesDatabase

Dim session3 As New NotesSession

Dim doc3 As NotesDocument

Dim view As NotesView

Dim vc As NotesViewEntryCollection

Dim entry As NotesViewEntry

Dim session2 As New NotesSession

Dim mailfilename2 As String

Dim db2 As NotesDatabase

Dim db4 As NotesDatabase

Dim session4 As New NotesSession

Dim doc4 As NotesDocument

Dim entry2 As NotesViewEntry

Dim view2 As NotesView

Dim vc2 As NotesViewEntryCollection

Dim processed As Variant	

Dim processed1 As NotesItem



Dim deptdate22 As NotesDateTime

Set db4 = session4.GetDatabase("Tornotes01/Alcatel","delegate.nsf")





Set view2 = db4.GetView("Out of Office Database")

Set vc2 = view2.AllEntries

If vc2.count = 0 Then

	Exit Sub

End If



Set entry2 = vc2.GetFirstEntry

While Not (entry2 Is Nothing)

	Set doc4 = entry2.document

	processed = doc4.GetItemValue("processed")

	If processed(0) = "NO" Then

		departuredat = doc4.GetItemValue("Departure")

		Set deptdate2 = New NotesDateTime(departuredat(0))

		Set deptdate22 = New NotesDateTime(deptdate2.LSLocalTime)

		Call todaysdate.SetNow

		Set todaysdate2 = New NotesDateTime(todaysdate.DateOnly)

		

		If deptdate22.LSLocalTime <= todaysdate2.LSLocalTime Then

			authorname = doc4.GetItemValue("Author")

			usersname = doc4.GetItemValue("Name")

			returndat = doc4.GetItemValue("Return")

			delegate = doc4.GetItemValue("Delegate")

			mailfilename = doc4.GetItemValue("mailfilename")

			details1 = doc4.GetItemValue("awaymessage")

			details = details1(0)

			Dim departuredate As String

			departuredate = departuredat(0)

			Dim returndate As String

			returndate = returndat(0)

			GeneralSubject = usersname(0) + " is out of the office"

			DaysOut = "I will be out of the office starting " + departuredate + " and will not return until " + returndate

			

			GeneralMessage = details

			

			Set db = session.GetDatabase(db4.Server, mailfilename(0))

			Set doc = db.GetProfileDocument("OutOfOfficeProfile")

			Set agent = db.GetAgent("OutOfOffice")

			

			If agent.IsEnabled = True Then

				agent.IsEnabled = False

				Call agent.Save

			End If

			

			Set deptdate1 = doc.ReplaceItemValue("FirstDayOut","")

			Set retdate1 = doc.ReplaceItemValue("FirstDayBack","")

			Set bookbusytime1 = doc.ReplaceItemValue("BookBusyTime","")

			Set GeneralSubject1 = doc.ReplaceItemValue("GeneralSubject", "")

			Set DaysOut1 = doc.ReplaceItemValue("DaysOut", "")

			Set DaysOut_1= doc.ReplaceItemValue("DaysOut_1","")

			Set datefirstdayback = doc.ReplaceItemValue("dateFirstDayBack","")

			Set datefirstdayout = doc.ReplaceItemValue("dateFirstDayOut","")

			Set GeneralMessage1 = doc.ReplaceItemValue("GeneralMessage","")

			Call doc.Save(True,True)

			

			Set deptdate1 = doc.ReplaceItemValue("FirstDayOut",departuredat(0))

			Set retdate1 = doc.ReplaceItemValue("FirstDayBack",returndat(0))

			Set bookbusytime1 = doc.ReplaceItemValue("BookBusyTime","1")

			Set GeneralSubject1 = doc.ReplaceItemValue("GeneralSubject", GeneralSubject)

			Set DaysOut1 = doc.ReplaceItemValue("DaysOut", DaysOut)

			Set DaysOut_1= doc.ReplaceItemValue("DaysOut_1","")

			Set datefirstdayback = doc.ReplaceItemValue("dateFirstDayBack",returndat(0))

			Set datefirstdayout = doc.ReplaceItemValue("dateFirstDayOut",departuredat(0))

			Set GeneralMessage1 = doc.ReplaceItemValue("GeneralMessage", GeneralMessage)

			Call doc.Save(True,True)

			If agent.IsEnabled = True Then

				agent.IsEnabled = False

				Call agent.Save

			End If

			If agent.IsEnabled = False Then

				agent.IsEnabled = True

				Call agent.Save

			End If

			Set processed1 = doc4.ReplaceItemValue("processed", "YES")

			Set processed1 = doc4.ReplaceItemValue("Processed1","YES")

			Call doc4.Save(True,True)

		Else

		End If	

	Else

	End If

	Set entry2 = vc2.GetNextEntry(entry2)

Wend

End Sub

Subject: I am having trouble executing a scheduled agent. I have read all the FAQ’s and can’t find the answer.

I would add print statements to see where the logic goes wrong. You can also run remote debugger to single step through the code.

I would also add error processing. This will tell you if you hitting an error in your code! If you don’t know how to do it, there is a sample in the help (and in the Agent FAQ that you mentioned).

Subject: Re: I am having trouble executing a scheduled agent.

Plus, look in the misc events in log.nsf to see whether the server is posting any error messages.