Sort NotesDocumentCollection By ItemName

// Sorts a NotesDocumentCollection by item name
// @param col, unsorted NotesDocumentCollection
// @param iName, the name of the item to sort the collection by.
// @return sorted NotesDocumentCollection
// @author Ulrich Krause
// @version 1.0
function sortColByItemName(col:NotesDocumentCollection, iName:String) {
	var rl:java.util.Vector = new java.util.Vector();
	var doc:NotesDocument = col.getFirstDocument();
	var tm:java.util.TreeMap = new java.util.TreeMap();

	while (doc != null) {
    	tm.put(doc.getItemValueString(iName), doc);                   
  		doc = col.getNextDocument(doc);

	var tCol:java.util.Collection = tm.values();
	var tIt:java.util.Iterator  = tCol.iterator();

	while (tIt.hasNext()) {

	return rl;	
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
1 comment(s)Login first to comment...
Andrew Grabovetskyi
(at 03:51 on 06.11.2013)
Nice example! ..but there is one warning: in case two or more documents have the same value of "doc.getItemValueString(iName)" - only one document will get in resulting rl:java.util.Vector.