I have code (ssjs) that should select a number of documents from a view based on a key that column 1 of the view is sorted on. The selection (according to getCount() shows 8 documents are in the collection but getFirstDocument() return "null" so that loop processing the documents does not get executed.
Below is the code. The while loop never gets executed because getFirstDocument() returns "null" even though getCount() says there are 8 documents in the collection, which is the number I am expecting and is the same as I get if I manually search the view with the key that it being used.
//*---------------------------------------------------------
//* Prime the loop
//*---------------------------------------------------------
var dcCpt:NotesDocumentCollection = vwCpt.getAllDocumentsByKey(rstrSerId)
if (bfDebug === true) {
print (strDCon + "Number CptCode .. '" + dcCpt.getCount() + "'")
}
var docTmp:NotesDocument;
var docCpt:NotesDocument = dcCpt.getFirstDocument();
if (docCpt == null) {
print (strDCon + "First Document is 'null' !!!!!")
}
//*---------------------------------------------------------
//* Process EVERY document
//*---------------------------------------------------------
while (docCpt !== null ){
The console output for the above is:
*** DEBUG *** ssjsAppFunc:getCptItems - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*** DEBUG *** ssjsAppFunc:getCptItems - STARTING
*** DEBUG *** ssjsAppFunc:getCptItems - rstrSrvId ..... 'SRV-02B57R5P'
*** DEBUG *** ssjsAppFunc:getCptItems - rstrSerId ..... 'SER-09APZJ9A'
*** DEBUG *** ssjsAppFunc:getCptItems -
*** DEBUG *** ssjsAppFunc:getCptItems - Getting CPT Codes
*** DEBUG *** ssjsAppFunc:getCptItems - Number CptCode .. '8'
*** DEBUG *** ssjsAppFunc:getCptItems - First Document is 'null' !!!!!
*** DEBUG *** ssjsAppFunc:getCptItems - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- I have used this construct 100's of times before and must be doing
something stupid, but for the life of me cannot see what it is. Any
thoughts / suggestions welcome.

Are there by any chance any
Readersfields on the documents that you retrieve?You could try a simple test to check if something like that may be the issue. Try to use
dcCpt.getNthDocument(i)to the other documents in the collection to see if they are also null - or you can see the contents of some of them? If you can see some of the documents then that may help you in discovering the issue :-)/John