getNthDocument (NotesDocumentCollection - JavaScript)

Gets the document at a specified position in a collection.

Defined in

NotesDocumentCollection

Syntax

getNthDocument(n:int) : NotesDocument
Parameter Description
n A number indicating the document to return. Use 1 to indicate the first document in the collection, 2 to indicate the second document, and so on.
Return value Description
NotesDocument The document at the nth position in the collection. If there is no document at the specified position, returns null.

Usage

Collections are renumbered when deletions occur so that the positions of documents after the deleted document change.

Using getNthDocument in conjunction with getCount to iterate through a loop is strongly discouraged for performance reasons. See getNextDocument and getPrevDocument for the preferred loop structures.

Examples

This button gets the next document in the current database modulo the total document count. A global variable specifies the current position.
var dc:NotesDocumentCollection = database.getAllDocuments();
var n:int = sessionScope.documentNumber;
if (dc.getCount() > 0) {
	if (n == null || n == dc.getCount()) {
		n = 1;
	} else {
		n++;
	}
	var doc:NotesDocument = dc.getNthDocument(n);
	requestScope.status = doc.getItemValueString("subject");
	doc.recycle();
	sessionScope.documentNumber = n;
}