view.getNextDocument in scheduled Java agent

I have a scheduled Java agent that cycles through the documents in a view. It updates a field in the doc, then saves the doc. I have taken care to retrieve the next doc in the view BEFORE saving the changes to the doc, as the changes made to the doc would cause it to disappear from the view. My code is as follows:

Document doc=view.getFirstDocument();

Document nextdoc=view.getFirstDocument();

while (doc!=null){

//changes made to doc here

nextdoc=view.getNextDocument(doc);

doc.save(true,true,false);

doc=nextdoc;}

Yet, I’m still getting a “Document argument is null” error when the agent runs out of docs to process in the view:

06/22/2004 13:55:15 AMgr: Agent (‘PostAgreementProcessing’ in ‘test/ecashierv3.nsf’) error message: NotesException: Document argument is null

06/22/2004 13:55:15 AMgr: Agent (‘PostAgreementProcessing’ in ‘test/ecashierv3.nsf’) error message: java/lang/Throwable.()V+4 (Throwable.java:73)

06/22/2004 13:55:15 AMgr: Agent (‘PostAgreementProcessing’ in ‘test/ecashierv3.nsf’) error message: java/lang/Exception.()V+1 (Exception.java:24)

06/22/2004 13:55:15 AMgr: Agent (‘PostAgreementProcessing’ in ‘test/ecashierv3.nsf’) error message: org/omg/CORBA/UserException.()V+1 (UserException.java:25)

06/22/2004 13:55:15 AMgr: Agent (‘PostAgreementProcessing’ in ‘test/ecashierv3.nsf’) error message: lotus/domino/local/View.getNextDocument(Llotus/domino/Document;)Llotus/domino/Document;+24 (:??)

I’ve searched this forum, and found a couple of other suggestions, which I’ve implemented to no avail:

  1. I changed the indexing on the view to “Manual”,so the index on the view wouldn’t update during the time this agent is running

  2. I tried using ViewNavigator to traverse through the docs in the view. This results in a different error: “Entry not found in index”.

Does anyone have any other suggestions? I’ve done a lot of LotusScript, but am new to Java. Thanks !!

Subject: setAutoUpdate method

Try using the ‘setAutoUpdate’ method to prevent the view from being updated while your agent loops through it.

Subject: RE: setAutoUpdate method

Lawrence, thanks for your reply. This fixed the problem !!! I set the AutoUpdate property as follows, and it did the job:

view.setAutoUpdate(false);

Thanks for your help - I really appreciate it !

Subject: view.getNextDocument in scheduled Java agent

Have you tried:

Document doc=view.getFirstDocument();

Document nextdoc;

while (doc!=null){

//changes made to doc here

nextdoc=view.getNextDocument(doc);

doc.save(true,true,false);

doc.recycle();

doc=nextdoc;

}

How many docs are in the view?

Steve

Subject: RE: view.getNextDocument in scheduled Java agent

Hi Steve - thanks for your reply. In another post, Lawrence suggested I set the view’s AutoUpdate property as follows, and this fixed the problem:

view.setAutoUpdate(false);

I also added doc.recycle() to the code as you suggested, since I’ve heard that’s a good thing to do to help prevent memory leaks. I am testing this with only 3 docs in the view, but there will be many more in production. Thanks for your help - I appreciate it !!