getFirstDocument() returns 'null' for a collection which getCount() says has 8 items

89 views Asked by At

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.
2

There are 2 answers

2
John Dalsgaard On

Are there by any chance any Readers fields 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

1
Trevor Denner On

The issue appears to have been that the "type" of the Database in the Application Properties was set to "Multi DB Search". I changed this to "Standard" and ran fixup and updall. This seemed to fix the issue.

enter image description here

I have no idea why this caused my issue or why changing it would fix the issue. I had already run fixup and updall (as the issue appeared to be with the view) with no effect, so suspect these may not have been required to fix the problem, but I did them anyway.