VladP
VladP

Reputation: 901

Notes error: Entry not found in index when reading view entries

My xPage SSJS fails in line:

viewEntry = view.getNext(viewEntry);

with error

Notes error: Entry not found in index

I do have this options set to false but it doesn't help:

view.setAutoUpdate(false);

So I suspect that it fails because user has not access to NEXT document because of reader access set. So such document cannot be seen in the view but in TOTALS. How to fix it?

The side problem is that if crashes Domino server then

Here is my code:

var view:NotesView = database.getView("xxxxxxx");
view.setAutoUpdate(false);
var viewNav:NotesViewNavigator = view.createViewNav();
var viewEntry:NotesViewEntry = viewNav.getFirst();

while (viewEntry != null) {
    if (viewEntry.isCategory()){
        // I work with category entry data
    } else if(viewEntry.isTotal()){
        // I collect totals
    } else {
        // I work with view entry
    }

    var tmpEntry:NotesViewEntry = viewNav.getNext(viewEntry);
    viewEntry.recycle();
    viewEntry = tmpEntry;
}

It fails in line: viewNav.getNext(viewEntry)

Script interpreter error, line=1001, col=37: [TypeError] Exception occurred calling method NotesViewNavigator.getNext(lotus.domino.local.ViewEntry)
Notes error: Entry not found in index ((xxxxxxx))
tmpEntry:NotesViewEntry = viewNav.getNext(viewEntry);

So how do I really go to next entry if current or next one is invalid?

Upvotes: 7

Views: 1555

Answers (3)

Paul Stephen Withers
Paul Stephen Withers

Reputation: 15729

It may also be worth verifying which entry is not found in index. It could be the first, depending on the context of your code. For example, it might have been updated to take it out of the view. Check for null first. Reader access may also be an issue, if you're working from a ViewNavigator, there are different reasons for access. Use a try/catch to also verify your hypothesis - sessionAsSigner (or ODA's native session) will have access to the next document, which will allow logging to confirm. Once you can confirm the cause, you can code around it.

ViewEntry.isValid() verifies if a soft deletion or user does not have access, as stated in documentation for ViewEntry and Document, which both have the same method.

Upvotes: 2

Frantisek Kossuth
Frantisek Kossuth

Reputation: 3524

Combine Ferry's answer (get next entry in advance) with the check of validity of the entry: https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_ISVALID_PROPERTY_2176.html

That should avoid your problem. Also, use try/catch block to identify what is the last processed document and take a closer look at it (and the next one). It may be corrupted.

Upvotes: 0

Ferry Kranenburg
Ferry Kranenburg

Reputation: 2635

Use the view navigator. If the user can not access the entry then a simple check with viewentry.getUniversalId() will return null, and so you could even skip it inside the view entries iteration.

Try this code instead:

        view.setAutoUpdate(false); 
        ViewNavigator nav = view.createViewNav();           
        ViewEntry entry = nav.getCurrent(); 
        ViewEntry nextEntry = null;
        while (entry != null) {
            if (entry.isCategory()) {
                nextEntry = nav.getNextSibling();
            } else {
                nextEntry = nav.getNext();
            }

            if (!entry.isTotal()) {

                // do something with the entry

            } else {
                // skipped entry
            }       

            //don't forget to recycle! 
            entry.recycle(); 
            entry = nextEntry;
        }
        view.setAutoUpdate(true); 

Upvotes: 0

Related Questions