Reputation: 2030
In IBM Lotus Domino I have built a Java Agent. In this agent I am getting a View which has orderlines:
View orderLinesView = CurrentDatabase.getView("OrderLinesOnId");
The view has a sorted column: ID_Order which is also categorized.
I did the following to get all documents in the view with the same ID_Order:
Vector keyRegel = null;
keyRegel = new Vector();
keyRegel.add(orderDocument.getItemValueString("ID_Order"));
DocumentCollection orderLineCollection = orderLinesView.getAllDocumentsByKey(keyRegel, true);
Now I want to loop through all the documents and print the description:
System.out.println("Count orderRegelcollection:" +
Document orderLineDocument = orderLineCollection.getFirstDocument();
while (orderLineDocument != null) {
System.out.println("description " + orderLineDocument.getItemValueString("description"));
orderLineDocument = orderLineCollection.getNextDocument();
}
On running, it does print 1 document and after the first loop it finishes. However, in my view I clearly see 5 documents with the same ID_Order. The strange thing is that it takes only the last document in the view (when I searched on ID_Order)
The complete code is like this:
View relationsView = dbRelatie.getView("Relations");;
Document relationDocument = relationsView.getFirstDocument();
while (relationDocument != null) {
Vector key = null;
key = new Vector();
key.add("");
key.add(relationDocument.getItemValueString("getDebtor"));
DocumentCollection orderDocumentCollection = TotalOrdersView.getAllDocumentsByKey(key, true);
Document orderDocument = orderDocumentCollection.getFirstDocument();
while (orderDocument != null) {
And then i get the orderlines..
Upvotes: 1
Views: 289
Reputation: 421
Your while loop is never getting the next document.
In you while loop change the last line to
orderLineDocument = orderLinesView.getNextDocument();
Also, alternatively since you have already built a collection. You can use that to get next document as
orderLineDocument = orderLineCollection.getNextDocument();
From the documentation an example class looks like this. This example although is getting all documents in database and creates DocumentCollection. The difference between your code and below example is that you are creating the collection from the view. Nonetheless this method should work for you too.
This agent gets all the documents in a database.
import lotus.domino.*; public class JavaAgent extends AgentBase { public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); // (Your code goes here) Database db = agentContext.getCurrentDatabase(); DocumentCollection dc = db.getAllDocuments(); Document tmpdoc; Document doc = dc.getFirstDocument(); while (doc != null) { System.out.println(doc.getItemValueString("Subject")); tmpdoc = dc.getNextDocument(); doc.recycle(); doc = tmpdoc; } } catch(Exception e) { e.printStackTrace(); } } }
Documentation for DocumentCollection
Upvotes: 1