Reputation: 153
I'm doing a while loop to get records in a categorised view. I want to return only the first record that meet the if condition and not the whole category. The code below returns all the records in the category that passed the 'if' condition.
var vView:NotesView = database.getView("Document");
var doc:NotesDocument = vView.getFirstDocument();
while(doc != null){
if(doc.getItemValueString("Status") == 'Live'){
//get the first in the category here where condition is met
var pVersion = doc.getItemValueString("Version");
var pPro = doc.getItemValueString("Pro");
}
var tmpDoc:NotesDocument = vView.getNextDocument(doc);
doc.recycle();
doc = tmpDoc;
}
View below:
The arrow shows the records that I would like to return.
Upvotes: 0
Views: 152
Reputation: 153
var vView:NotesView = database.getView("Document");
var doc:NotesDocument = vView.getFirstDocument();
var product;
while(doc != null){
if(product != doc.getItemValueString("Product")){
//get only the first in the category
var pVersion = doc.getItemValueString("Version");
var product = doc.getItemValueString("Product");
}
var tmpDoc:NotesDocument = vView.getNextDocument(doc);
doc.recycle();
doc = tmpDoc;
}
Upvotes: 0
Reputation: 940
Try breaking out of the loop once the doc is found:
var vView:NotesView = database.getView("Document");
var doc:NotesDocument = vView.getFirstDocument();
var done = false;
while(doc != null && !done){
if(doc.getItemValueString("Status") == 'Live'){
//get the first in the category here where condition is met
var pVersion = doc.getItemValueString("Version");
var pPro = doc.getItemValueString("Pro");
done = true;
}
var tmpDoc:NotesDocument = vView.getNextDocument(doc);
doc.recycle();
doc = tmpDoc;
}
Upvotes: 1
Reputation: 20384
Your graphic suggest you want the first document in each category that meets a condition?
For the question as asked:
var continueSearch = true
while(doc != null && continueSearch) {
if(...) {
...
continueSearch = false;
}
...
}
That should do it
Upvotes: 2