Samuel Omopariola
Samuel Omopariola

Reputation: 153

Xpages: How to get only the first record of a categorised view

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:

enter image description here

The arrow shows the records that I would like to return.

Upvotes: 0

Views: 152

Answers (4)

Samuel Omopariola
Samuel Omopariola

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

teleman
teleman

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

stwissel
stwissel

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

umeli
umeli

Reputation: 1068

Did you look at the notesviewnavigator class ?

Upvotes: 1

Related Questions