I have an agent that I have been testing that does not want to process all required documents. Here is some of the code:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim dateTime As NotesDateTime
Set db = session.CurrentDatabase
Set dateTime = New NotesDateTime( "Today" )
Set view = db.GetView( "byStatus" )
Set doc = view.GetFirstDocument
While Not(doc Is Nothing)
If doc.SerialNumber(0) <> "" Then
(bunch of code)
saveDoc:
doc.dateBPupdate = dateTime.LocalTime
Call doc.Save (True, True)
Set doc = view.GetNextDocument(doc)
Wend
End Sub
I am running the agent this way. I select the database, then select the agent from the actions menu (I want the agent to be eventually run “On schedule”)
The Agent properties are:
Shared
Trigger: On event
Run Time: Action Menu selection
Target: All documents in the database
The agent will process only one document in the view and then quit. No error messages. I have set the Target several differt ways, but none will work (some get error messages). Any ideas or help would be appreciated. Thanks.
Subject: You have 2 solutions:
Either: view.AutoUpdate = False
While Not(doc Is Nothing)
If doc.SerialNumber(0) <> "" Then
Or:
Dim nextdoc As NotesDocument
…
While Not(doc Is Nothing)
If doc.SerialNumber(0) <> "" Then
doc.dateBPupdate = dateTime.LocalTime
Set nextdoc = view.GetNextDocument(doc)
Call doc.Save (True, True)
Set doc = nextdoc
End If
Wend
Subject: Agent not running properly
You are managing to update the first document. Does the update affect it’s position in the view after updating? For example, however you’re sorting the view, after you update the document, it could become the last document in the view so when your program processes the “next” document in the view, there are no more so it terminates.
Otherwise, walk thru the program with the debugger on to see why it’s doing what it’s doing.
Also, if running the agent interactively, try changing the Target to “None”. That’s supposed to be equivalent to the R5 “Run once (@Commands may be used)”.
Hope that helps.
Subject: RE: Agent not running properly
Wing Mar, you were right on about the position in the view. The first doc in the view DID become the last after the update. I created a view for just this agent to run on, with the category changed to a non category unsorted so that when the doc was updated it did not change its position in the view and it RAN LIKE A CHAMP. Thanks to all for your time and help.