GetNextDocument - not recognizing document

After upgrading to R6 the following code skips some documents in the view at the “Set docGC = viewGC.GetNextDocument(docGC)” line.

Sub GetCourtesy(dbC As NotesDatabase, officerNum As Variant, statusCt As Integer)

Set viewGC = dbGC.GetView("openCasesbyOrigOfcr#")

Set docGC = viewGC.GetDocumentByKey(officerNum,True)	



CCstsCatCd(0) = "TRANSFERRED"

CCStsNm(0) = "COURTESY CASES"



If Not (docGC Is Nothing) And Not(AdminTotal) Then

	Call Headings

End If



Do While Not(docGC Is Nothing)

	DOCNum       = docGC.DOCNum

	dspOfnName = docGC.dspOfnName

	

	If DOCNum(0) = saveDOCNum Then

		Goto skipthisone

	End If

	saveDOCNum = DOCNum(0)

	

	Call GetDataSubs

	If Not(AdminTotal) Then

		Call RptBody.AppendText(dspOfnName(0) & " " & DOCNum(0))

		If MultipleCases = "True" Then

			Call RptBody.AppendText("      *****") 'added 6/07/2002 mtt

		End If

		Call RptBody.AddNewLine(1) 'added 7-12-2000  ajm

		Call RptBody.AppendText("                    ") ' added 20 spaces 7-12-2000 ajm

		Call RptBody.AppendText(riskLevelNm)

		Call RptBody.AddTab(1)

'Flag if Projected Completion Date is within 30 days of today.

		If Isdate(crtCseEcd) Then

			If (Datevalue(crtCseEcd) - Today) <  31 Then

				rtStyle.Bold = True

				rtStyle.NotesColor = COLOR_RED

				Call RptBody.AppendStyle(rtStyle)          

				

				crtCseEcd = ">" + crtCseEcd + "<" 

			End If     

		End If

		

		Call RptBody.AppendText(crtCseECD)

		

		rtStyle.Bold = False

		rtStyle.NotesColor = COLOR_BLACK

		Call RptBody.AppendStyle(rtStyle)

		

		Call RptBody.AddTab(1)

		Call RptBody.AppendText(riskNeedsDateTxt)

		Call RptBody.AddTab(1)

		Call RptBody.AppendText(supPlnCreateDtTxt)

		Call RptBody.AddTab(1)

		Call RptBody.AppendText(supPlnNextDtTxt)

		Call RptBody.AddTab(1)

		Call RptBody.AppendText(pgmAssgnDtTxt)

		Call RptBody.AddNewLine(1)

	End If	

	statusCt = statusCt + 1

	

     '**************************************

			' Add count to correct bucket in table for courtesy transfers

	

	If riskLevelNm = "ISL 1" Or riskLevelNm = "ISL I" Then

		TotalNumb(20,1,1) = TotalNumb(20,1,1) + 1

		TotalNumb(20,1,2) = TotalNumb(20,1,2) + 1

		TotalNumb(21,1,1) = TotalNumb(21,1,1) + 1

		TotalNumb(21,1,2) = TotalNumb(21,1,2) + 1

	Elseif riskLevelNm = "ISL 2" Or riskLevelNm = "ISL II" Then

		TotalNumb(20,2,1) = TotalNumb(20,2,1) + 1

		TotalNumb(20,2,2) = TotalNumb(20,2,2) + 1

		TotalNumb(21,2,1) = TotalNumb(21,2,1) + 1

		TotalNumb(21,2,2) = TotalNumb(21,2,2) + 1

	Elseif riskLevelNm = "ISL 3" Or riskLevelNm = "ISL III" Then

		TotalNumb(20,3,1) = TotalNumb(20,3,1) + 1

		TotalNumb(20,3,2) = TotalNumb(20,3,2) + 1

		TotalNumb(21,3,1) = TotalNumb(21,3,1) + 1

		TotalNumb(21,3,2) = TotalNumb(21,3,2) + 1

	Elseif riskLevelNm = "ISL IV" Then

		TotalNumb(20,4,1) = TotalNumb(20,4,1) + 1

		TotalNumb(20,4,2) = TotalNumb(20,4,2) + 1

		TotalNumb(21,4,1) = TotalNumb(21,4,1) + 1

		TotalNumb(21,4,2) = TotalNumb(21,4,2) + 1

	Else

		TotalNumb(20,5,1) = TotalNumb(20,5,1) + 1

		TotalNumb(20,5,2) = TotalNumb(20,5,2) + 1

		TotalNumb(21,5,1) = TotalNumb(21,5,1) + 1

		TotalNumb(21,5,2) = TotalNumb(21,5,2) + 1

	End If

	

	

      '*************************************************************************************

skipthisone:

	Set docGC = viewGC.GetNextDocument(docGC)

	If Not (docGC Is Nothing)   Then

		If docGC.crtCseOfficerNum(0) <> officerNum Then

			Exit Do

		End If

	End If          

	

Loop

If Not (docGC Is Nothing) Then

	If Not(AdminTotal) Then

		Call RptBody.AddNewLine(1)

		rtStyle.Bold = True

		Call RptBody.AppendStyle(rtStyle)

		Call RptBody.AppendText("*   Total " & CCStsNm(0))

		Call RptBody.AddTab(1)

		Call RptBody.AppendText(Str(statusCt))

		Call RptBody.AddNewLine(1)

		Call RptBody.AppendText("------------------------------------------------------------------------------------")

		Call RptBody.AppendText("------------------------------------------------------------------------------------")

		Call RptBody.AddNewLine(1)

		rtStyle.Bold = False

		Call RptBody.AppendStyle(rtStyle)

	End If

End If

End Sub

  1. If I remove the devil document from the view, the code continues until it hits the next devil document. How can I compare the documents to see how they are different from the ones that are cycling through the code? Each form has about 50 fields on it. (Documents were created PRIOR to upgrade).

  2. If I run this code in R5, it works.

Please help - I’m on my last few fists of hair.

Subject: RE: GetNextDocument - not recognizing document

Erroring out is not the same thing as skipping a document. Which is it, or is it both on different occasions?

If you use GetAllDocumentsByKey, you can remove that silly test for whether the next document matches the key you were given. If it matters whether you process the documents in view order, use GetAllEntriesByKey. If there actually is some kind of bug affecting GetNextDocument, using NotesViewEntryCollection is also likely to be a workaround.

The error message you are getting, in this context, hints at a cache problem. When you get a NotesDocument object (let’s say you get it from view A) for the first time, Notes caches it. The object contains information about what view it was read from and what its position was in the view. This is needed for GetNextDocument to work, because if the document appears more than once in the same view, you need to be sure to get the “right” next document.

If in that same script you later encounter the same NotesDocument object while scanning view B, LotusScript uses the cached copy it got from view A. You can’t GetNextDocument of that document with respect to view B, because it didn’t originally come from view B. It has information in it saying, “I came from row number x of view A.”

When working with NotesDocument objects in views, it’s important to use the Delete statement to clear the object from cache when you are done with it. This not only makes your script work more reliably when reading the same documents from multiple views, but it also prevents you from using up lots of memory if you process large numbers of documents in the same script.

You can also avoid the caching problem by using NotesViewEntry objects to navigate the view rather than NotesDocument.

Incidentally, if you can arrange to use a view that displays the values you need in its columns, you can access those values directly from NotesViewEntry.ColumnValues (or NotesDocument.ColumnValues). This is a lot more efficient than reading the fields from the documents.

Subject: GetNextDocument - not recognizing document

One more thing - error I receive:

The Document is not in View openCasesbyOrigOfcr#

Thanks.