7

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?

VladP
  • 811
  • 2
  • 10
  • 26
  • You mentioned that you're concerned about a Totals entry, so I presume you are using the NotesViewNavigator class. A total or subtotal is accessible even if you don't have access to any of the documents included in the total. Have you tried looking at viewEntry.isTotal and if it is true calling createViewNavFromChildren() to create a new navigator containing only documents that were included in this total, and then looking at the Count property for the new navigator to see if it's zero? – Richard Schwartz Sep 19 '18 at 23:33
  • I know that Totals are accessible regardless of users' rights.. So I'm trying to navigate through entire view then getting that error (even view autoUpdate is false) – VladP Sep 20 '18 at 21:55
  • 1
    Can you inlcude the [mcve] into your question? – nempoBu4 Sep 25 '18 at 08:28
  • Do you DELETE documents inside your loop? – Frantisek Kossuth Sep 25 '18 at 09:28
  • In your error message there is `viewEntry = viewNav.getNext(viewEntry);`. But there is no `viewEntry = viewNav.getNext(viewEntry);` line of code in your example. Make sure that you provided correct example, please. – nempoBu4 Sep 26 '18 at 15:44
  • the example is correct.. Sorry for typo in error message when I copied it from logs – VladP Sep 26 '18 at 19:14

3 Answers3

2

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.

Paul Stephen Withers
  • 15,599
  • 1
  • 13
  • 33
  • Let's say user has no access to the record. And I understand that Totals are always available. So how do I skip that record then and proceed to the next one? – VladP Sep 20 '18 at 04:00
  • 1
    It would be easier to answer that if you posted your code, not just isolated lines of code. – Richard Schwartz Sep 21 '18 at 22:06
  • See updated answer. But you need to verify reader access actually is the cause. The key to the right solution for any problem is being certain of the cause. – Paul Stephen Withers Sep 26 '18 at 13:03
  • How can I check whether the entry if valid if I cannot get to it.. It fails here: viewNav.getNext(viewEntry); The current entry is valid but I cannot get the next one – VladP Sep 27 '18 at 14:34
  • You need to verify the cause of the error. The documentation says lack of reader access will give a ViewEntry that's not valid. That's my experience too. `Entry not found in index` implies to me a failure on the `viewEntry` being passed to `getNext()`, not that the API is getting the next and finding that it's not in the index. – Paul Stephen Withers Sep 28 '18 at 01:42
  • How there can be `viewEntry` in view to which user have no reader access? The view is intended to show only those entries to which the user have access. Its a fundamental of how views are working. – nempoBu4 Sep 28 '18 at 06:29
  • The 'previous' viewEntry is the cause of the problem I think. You should check it first, like my answer: viewentry.getUniversalId(). It that returns null or an Exception you should skip it. It could be protected by a reader field or it is a conflict entry. Sometimes even the viewindex is corrupt. Just call getNext() instead of getNext(viewEntry). – Ferry Kranenburg Oct 02 '18 at 20:46
  • @FerryKranenburg The condition in while cycle is `viewEntry != null`. But if viewindex is corrupt then its administrator job, not programmer problem. Administrator should fixup the index and perform maintenance on base. – nempoBu4 Oct 03 '18 at 06:32
0

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); 
Ferry Kranenburg
  • 2,073
  • 1
  • 15
  • 21
0

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.

Frantisek Kossuth
  • 3,640
  • 2
  • 21
  • 40
  • viewEntry.isValid() doesn't really help. It fails in getNext(entry). So even I use try/catch block how do I navigate to next valid entry? I've updated original question – VladP Sep 26 '18 at 14:43