This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jul 31, 2013, 6:24 PM
453 Posts
topic has been resolvedResolved

Looping through a collection in SSJS

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 9.0
  • Role: Developer
  • Tags: ssjs
  • Replies: 4

In LotusScript I use the following to loop through a collection of Documents and I am having some issues with doing the same thing in SSJS

dim doc as NotesDocument

dim col as NotesDocumentCollection

set col = vw.getAllDocumentsbyKey("SomeKey")

set doc = col.getFirstDocument

While not(doc is Nothing)

do my stuff

set doc = col.getNextDocument(doc)

End While

However, when trying this in SSJS

var doc:NotesDocument = col.getFirstDocument

while (doc != "" | doc != null) {

doc = col.getNextDocument(doc)

}

if the collection count is zero in SSJS it appears to try to execute the code within the while so it would appear that doc != "" | doc != null is not equivalent to the LS not(doc is Nothing)

 

Jul 31, 2013, 6:30 PM
453 Posts
Got it!

I needed to just test for doc != null the | doc != "" was not needed and in fact caused the problem

Aug 1, 2013, 6:09 AM
54 Posts
while

var thisDB = session.getCurrentDatabase();
var v = thisDB.getView("view1");
var doc = v.getFirstDocument();

while(doc){
    print("Found doc");
    print(doc.getCreated());
    var doc = v.getNextDocument(doc);
}

 

OR

while(!doc){

Aug 1, 2013, 6:40 PM
586 Posts
recycle

don't forget...  any loop that has a domino object in should have some recycling going on.  You can crash a server if you don't.

 

This is from the Cheatshsheet and I think is still valid.

 

 

var doc:NotesDocument = collect.getFirstDocument();
var tmpDoc:NotesDocument
while (doc != null) {
tmpDoc = collect.getNextDocument();
// Insert Code here.  Work with the “doc” object.
doc.recycle();
doc = tmpDoc;

}


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal