Problem with agent using getalldocumentbykey and collection

Any idea why this agent does not pull any documents from the AllRequests view?

Dim agentLog As New NotesLog("Agent log")

Call agentLog.OpenAgentLog

On Error Goto errorhandling

Dim s As New notessession

Dim db As notesdatabase

Set db = s.currentdatabase



	' Report docs

Dim view As notesview

Dim doc As notesdocument

Dim routedoc As notesdocument

Set view = db.getview("AllReportingDocs")

Set doc = view.getfirstdocument

While Not (doc Is Nothing)

	Set routedoc = view.getnextdocument(doc)

	

	Dim defview As notesview

	Dim defcollect As NotesDocumentCollection

	Dim defdoc As notesdocument

	Dim defroute As notesdocument

	Set defview = db.getview("AllRequests")

	

	requestID=doc.Rpt(0)

	Set defcollect = defview.GetalldocumentsByKey(requestID)

	Set defdoc = defcollect.getfirstdocument

	

	While Not (defdoc Is Nothing)

		Set defroute = defcollect.getnextdocument(defdoc)

		agentLog.LogAction("found: "+defdoc.qNum(0))

nextdef:

		Set defdoc = defroute

	Wend

nextdoc:

	Set doc = routedoc

Wend

Thanks for your help!!!

Subject: problem with agent using getalldocumentbykey and collection

Well, first off, where you do your

requestID=doc.Rpt(0)

Set defcollect = defview.GetalldocumentsByKey(requestID)

have you verified that doc.Rpt(0) has a good value and that there are one or more docs in that view that will match on that key?

Also, these statements

Dim defcollect As NotesDocumentCollection

Dim defdoc As notesdocument

Dim defroute As notesdocument

Set defview = db.getview(“AllRequests”)

are within your first While loop. This means that for each doc processed in that loop, you keep dimming them over and over. I would move those outside of the loop, as you only need to Dim them once.

HTH

Subject: RE: problem with agent using getalldocumentbykey and collection

Hi!

I got one or more value in the AllRequests view and the first column for both views are sorted. Here is my code after new suggested changes and I still can not get any documents from the second view.

Dim agentLog As New NotesLog(“Agent log”)

Call agentLog.OpenAgentLog

On Error Goto errorhandling

Dim s As New notessession

Dim db As notesdatabase

Set db = s.currentdatabase

’ Report docs

Dim defview As notesview

Dim defcollect As NotesDocumentCollection

Dim defdoc As notesdocument

Dim defroute As notesdocument

Dim view As notesview

Dim doc As notesdocument

Dim routedoc As notesdocument

Set view = db.getview(“AllReportingDocs”)

Set doc = view.getfirstdocument

While Not (doc Is Nothing)

Set routedoc = view.getnextdocument(doc)

Set defview = db.getview(“AllRequests”)

Set defcollect = defview.GetalldocumentsByKey(doc.Rpt(0)) '===> from the first lookup

Set defdoc = defcollect.getfirstdocument

While Not (defdoc Is Nothing)

Set defroute = defcollect.getnextdocument(defdoc)

agentLog.LogAction("found: "+defdoc.qNum(0))

nextdef:

Set defdoc = defroute

Wend

nextdoc:

Set doc = routedoc

Wend

Thanks so much!!!

Subject: RE: problem with agent using getalldocumentbykey and collection

Ok, I made some changes to your code. One thing I noticed that I kind of referenced in my prev post was where you had

Set defview = db.getview(“AllRequests”)

within the primary loop, so I moved that outside of the loop with the other db.getview. I didn’t see any need to keep setting defview.

I also got rid of some NotesDocument assignments which didn’t seem to be needed if the GetNextDocument calls were moved to the bottom of the loops. Normally you would need to do something like that if you were deleting documents from a view and needed to maintain the ability to get the next doc after the deleted one.

Look this over and see if it might work any better.

'On Error Goto errorhandling

Dim s As New notessession

Dim db As notesdatabase

Set db = s.currentdatabase ' Report docs



Dim defcollect As NotesDocumentCollection



Dim view As notesview

Dim defview As notesview



Dim doc As notesdocument

Dim defdoc As notesdocument



'Dim defroute As notesdocument 

'Dim routedoc As notesdocument	



Dim agentLog As New NotesLog("Agent log")

Call agentLog.OpenAgentLog



Set view = db.getview("AllReportingDocs")

Set defview = db.getview("AllRequests")



Set doc = view.getfirstdocument

While Not (doc Is Nothing)		

	

	Set defcollect = defview.GetalldocumentsByKey(doc.Rpt(0)) '===> from the first lookup

	

	Set defdoc = defcollect.getfirstdocument

	

	While Not (defdoc Is Nothing)			

		agentLog.LogAction("found: "+defdoc.qNum(0))			

		Set defdoc = defcollect.getnextdocument(defdoc)			

	Wend		

	

	Set doc = view.getnextdocument(doc) 		

Wend

Subject: problem with agent using getalldocumentbykey and collection

Hmm. First, make sure AllRequests has the key as its first column and that it’s sorted. Make sure you have a valid key (it is in the same format as the first column). Your best bet is to turn on the debugger and examine all of the objects at each step until you get to where the code is failing.