Java, Looping, View and Remove

Ok Hope someone can help me here,

I have a database that has a view which contains documents that are “not processed” i.e. there (processedYN) field still has a value of “No”. What I am wanting to do is run a java agent and set these documents to “Yes” thereby removing them from my view and making them processed.

My problem is that when I am running my code like below:

View view = quotesdb.getView(“Quotes - Unprocessed”);

lotus.domino.Document dataDoc = view.getFirstDocument();

while (dataDoc != null) {

Do work set field to “Yes”

getNextDocument(dataDoc);

}

It is throwing errors because I am removing a document from the view while the agent is running so when the agent gos for the next document it is losing its place and therefore throws an error…

I need to essentially make the agent loop through the documents in view whilst setting the processedYN field to Yes and not lose its position when it trys to get the next document.

I hope you understand what Im trying to do and any help would be appreciated.

Thanks

Subject: Java, Looping, View and Remove

You could build a collection as you go along and perform stampall once the agent is done something like below…

View view = db.getView(“Unprocessed”);

//build empty collection

DocumentCollection col=view.getAllDocumentsByKey(“BLAH”,true);

Document doc = view.getFirstDocument();

while(doc!=null){

//here add your code to determine yes/no then add to the collection

if(true){

col.addDocument(doc);

}

doc=view.getNextDocument(doc);

}

//now you have your collection of “yes” docs.

col.stampAll(“fieldName”,“Yes”);

Subject: Java, Looping, View and Remove

Aden

You have 2 options:

  1. use the view.IsAutoUpdate property (set to false when you start and true when your code has finished)

  2. use a second lotus.domino.Document to assign your next document before you save the current one. e.g. nextDoc = getNextDocument(dataDoc), update dataDoc, dataDoc = nextDoc

(I think the first option is probably the cleanest :wink:

Ben)

Subject: RE: Java, Looping, View and Remove

doh…what was i thinking…view.setAutoUpdate(false); is the best solution …mine will only work if doesn’t recycle which means it can only process a small volume of docs before it blows up. again…all i can say…what was i thinking… :wink:

Subject: RE: Java, Looping, View and Remove

Firstly thank you both for your replies, I found bens IsAutoUpdate property to be the perfect solution to my needs.

Thanks again.

Aden Sykes