Reputation: 2030
I have a View with more than 2 documents inside. This is the code which grabs the document
Currently I have this:
Document orderRegelDocument = OrderRegelsVoorCopsView.getFirstDocument();
while (orderRegelDocument != null) {
//do something here
System.out.println("Nieuwe Orderregel");
tempOrderRegel = OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument);
orderRegelDocument.recycle(); // recycle the one we're done with
orderRegelDocument = tempOrderRegel;
}
The first document is getting grabbed but after that I get a NotesException: Notes error: Entry not found in index viewName. What am I doing wrong?
And also a question next to this. If a user is in a document, but my agent also changes a field then when the user saves the document it gets a save conflict. Is there a way to overcome this.
Upvotes: 0
Views: 1552
Reputation: 14628
You are apparently doing something in the code that you are not showing that is altering the view before you are calling getNextDocument
. You might be deleting the document, changing an item value that causes the document to no longer be selected for the view, or changing an item value that causes the document to be re-sorted to a different location in the view collection.
The idiom that is used to avoid this sort of thing is to make that call to getNextDocument
as one of the first things that it occurs in the body of your while loop. I.e., just move it up so that it occurs before your //do something here
code. Like this:
Document orderRegelDocument = OrderRegelsVoorCopsView.getFirstDocument();
while (orderRegelDocument != null) {
tempOrderRegel = OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument);
//do something here
System.out.println("Nieuwe Orderregel");
orderRegelDocument.recycle(); // recycle the one we're done with
orderRegelDocument = tempOrderRegel;
}
Upvotes: 1
Reputation: 7081
I don't know all of your code but my guess would be that assuming getNextDocument(document) gets the next and sets it in the document (otherwise you never assign it the getNext result to anything) you call getNextDocument() twice instead of once and you skip the second row and try to manupulate the 3rd (which is not present) and you get the error.
if( OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument) != null){ //Here you take the next
tempOrderRegel = OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument); //And here you take the next after
// Here you are at the wrong item already...
Upvotes: 1