Scheduling an agent to run on "all documents in a view"

I have an agent that has the Runtime Target = “All documents in View”. It’s running fine. But, now I want this agent to run at a certain time once a week. When I select “On Schedule”, it changes the Target options and “All documents in View” is not one of them. This is for a web application. How can I get my agent to run on a schedule using all the document in the view?

Subject: scheduling an agent to run on “all documents in a view”

“All documents in view” trigger is not valid on the web. You can see a list of triggers that not valid on the web in Agent FAQ’s article “Troubleshooting agents in R5 and R6”. You just need to select “All documents” and write the code that selects the view and goes through it.

Subject: RE: scheduling an agent to run on “all documents in a view”

I am now trying to get my agent to run using LotusScript and the problem is with the Do loop. When it reaches the end of the documents it displays an error message “Object variable not set”. Then it aborts the agent so the code that sends email that is after the Do loop doesn’t get executed. Here is my code:

Sub Initialize

Dim session As New NotesSession

Dim maildb As New NotesDatabase( "", "" )

Set maildb = session.CurrentDatabase

Set maildoc = New NotesDocument(maildb)

Dim count As Integer



Dim v As NotesView

' Instantiate view object

Set v = maildb.GetView ("lotusscriptover10daysold")

Set doc = v.GetFirstDocument

Messagebox doc.Vendor(0)

count = count + 1

Messagebox count

    v1 = doc.Vendor(0)

Do Until (doc Is Nothing)

	Set doc = v.GetNextDocument(doc)

	count = count + 1

	Messagebox doc.Vendor(0) 

	Messagebox count

Loop	

maildoc.Form = "Memo"

maildoc.Subject = "Test"

maildoc.Body = v1 & " " & doc.Vendor(0)

maildoc.SendTo = "test"

maildoc.CopyTo = "test"

Call maildoc.Send(False,maildoc.SendTo)	

End Sub

Subject: Try:

Sub Initialize Dim session As New NotesSession

Dim maildb As New NotesDatabase( "", "" )

Set maildb = session.CurrentDatabase

Set maildoc = New NotesDocument(maildb)

Dim count As Integer



Dim v As NotesView

' Instantiate view object

Set v = maildb.GetView ("lotusscriptover10daysold")

Set doc = v.GetFirstDocument

count = 0

Do Until (doc Is Nothing)

	If count = 0 Then

            		v1 = doc.Vendor(0)

	Else

		v1 = v1 + " " + doc.Vendor(0) 

	End If

	count = count + 1

	Messagebox v2 

	Messagebox count

	Set doc = v.GetNextDocument(doc)

Loop	

maildoc.Form = "Memo"

maildoc.Subject = "Test"

maildoc.Body = v1

maildoc.SendTo = "test"

maildoc.CopyTo = "test"

Call maildoc.Send(False,maildoc.SendTo)	

End Sub

Subject: RE: Try:

I still get the “Object variable not set” error message when it gets to the end of the Do loop (when it finishes reading in all the documents in the view).

Subject: Post your modified code please.

Subject: RE: Post your modified code please.

It seems to fail once there are no more documents in the view to read in. I get the error message “object variable not set”. If I change the Do loop to Do until count = 5 it works and does not display the “object variable not set” message.

Sub Initialize

Dim session As New NotesSession

Dim maildb As New NotesDatabase( "", "" )

Set maildb = session.CurrentDatabase

Set maildoc = New NotesDocument(maildb)

Dim count As Integer



Dim v As NotesView

' Instantiate view object

Set v = maildb.GetView ("lotusscriptover10daysold")

Set doc = v.GetFirstDocument

count = 0

Do Until (doc Is Nothing)

	If count = 0 Then

		v1 = doc.Vendor(0)

	Else

		v1 = v1 + " " + doc.Vendor(0) 

	End If

	count = count + 1

	Messagebox v1

	Messagebox count

	Set doc = v.GetNextDocument(doc)

Loop



maildoc.Form = "Memo"

maildoc.Subject = "Test"

maildoc.Body = v1 & " " & doc.Vendor(0)

maildoc.SendTo = "test"

maildoc.CopyTo = "test"

Call maildoc.Send(False,maildoc.SendTo)	

End Sub

Subject: Your problem is…

this line.maildoc.Body = v1 & " " & doc.Vendor(0)

since doc is already nothing, doc.Vendor(0) you get the object variable not set.

change it to

maildoc.Body = v1

you have already placed all vendors into v1 in your loop anyway.

Subject: RE: Your problem is…

That was it. Thanks Bill, it works now!!

Subject: scheduling an agent to run on “all documents in a view”

Hey there,

Just create a lotus script agent that loops through all the documents in a view or document collection. A Do while doc is Nothing loop works well.

HTH

Subject: RE: scheduling an agent to run on “all documents in a view”

I think you meant “do UNTIL doc is nothing”!