Search code examples
xpageslotus-noteslotus-dominoxpages-ssjsssjs

Xpages - Return correct documents using getDocumentByKey(unid, true)


I have a list, but I only want to narrow down my list to only documents with the current unid which appears on the browser, I did this by calling on the getDocumentByKey method of the viewEv object and pass in the unid arguement.

Strangly, this worked for only the newest document. The other documents, just shows all the list not belonging to the unid on the browser.

Any help will be appreciated.

Below is my code:

  function getCalObj(){ 
    var viewEv:NotesView = database.getView("Diary");
    viewEv.setAutoUpdate(false);    
    var docEv:NotesDocument = viewEv.getFirstDocument();
    var doc:NotesDocument = diaryDoc.getDocument();
    var sUNID = doc.getUniversalID();
    print("unid: " + sUNID);
    docEv = viewEv.getDocumentByKey(sUNID, true);

    while (docEv != null) {
      ........
    }
}

Solution

  • Use getAllDocumentsByKey() to get all documents with this sUNID.

    var dcEv:NotesDocumentCollection = viewEv.getAllDocumentsByKey(sUNID);
    if (dcEv.getCount() > 0) { 
        var docEv:NotesDocument = dcEv.getFirstDocument(); 
        while (docEv != null) { 
             ........ 
        }