2016-11-11 9 views
1

IBM Lotus DominoではJavaエージェントを構築しました。また、分類されID_OrderDocumentCollectionの数は5ですが、1つのドキュメントのみを取得します

View orderLinesView = CurrentDatabase.getView("OrderLinesOnId"); 

ビューがソートされた列があります。このエージェントでは、私は注文ラインを持っているビューを取得しています。

私は同じID_Orderとビューのすべての文書を取得するには、次のでした

Vector keyRegel = null; 
keyRegel = new Vector(); 
keyRegel.add(orderDocument.getItemValueString("ID_Order")); 
DocumentCollection orderLineCollection = orderLinesView.getAllDocumentsByKey(keyRegel, true); 

は今、私はすべてのドキュメントをループしたいと説明印刷:ランニングで

System.out.println("Count orderRegelcollection:" + 
Document orderLineDocument = orderLineCollection.getFirstDocument(); 

while (orderLineDocument != null) { 
    System.out.println("description " + orderLineDocument.getItemValueString("description")); 
    orderLineDocument = orderLineCollection.getNextDocument(); 
} 

をそれは1文書を印刷し、最初のループの後に終了します。しかし、私の見解では、同じID_Orderを持つ5つの文書がはっきりと分かります。 (私はID_Orderで検索する場合)奇妙なことが

enter image description here

完全なコードは次のようである、それはビューにのみ最後の文書を取ることです。

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) { 

そして私が得ます

答えて

1

あなたのwhileループは決して次のドキュメントを取得しません。ループはすでにコレクションを構築している代わりにするので、また

orderLineDocument = orderLinesView.getNextDocument(); 

への最後の行を変更しているときには

。これを使用して次のドキュメントを取得することができます

orderLineDocument = orderLineCollection.getNextDocument(); 

ドキュメントから、サンプルクラスは次のようになります。この例では、データベース内のすべてのドキュメントを取得しており、DocumentCollectionを作成しています。コードと以下の例の違いは、ビューからコレクションを作成していることです。それにもかかわらず、この方法もあなたのために働くはずです。

このエージェントは、データベース内のすべてのドキュメントを取得します。

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

+0

彼は)(私はorderLineCollection.getNextdocumentを持っていた申し訳ありませんいや。私は間違って質問にそれを入力..そして、なぜ私は100.000 +のドキュメントを介してループをしたくないためgetAllDocumentsByKeyを使用する理由 – YdB

+0

問題はありません。 :)これは、あなたが 'getAllDocuments()'や 'getDocumentByKeys()'のどちらかを使ってドキュメントコレクションを作ることができたと言った理由です。コレクションオブジェクトは次のドキュメントをループ、私は上記の方法で。 –

+0

:)返信ありがとう、私はorderLineCollection.getNextDocument()を持っています。しかし、私は最後の文書しか入手しません。だから私はビューでそれを見て5を参照してくださいしかし、私は最後を得る – YdB

関連する問題