ShowTable of Contents
Count
This computed field displays the number of documents in the current database.
return database.getAllDocuments().getCount().toFixed()
IsSorted
A button processing a document collection assigns the NotesDocumentCollection object to a global variable. This computed field queries the global variable and displays whether the collection is sorted.
var dc:NotesDocumentCollection = requestScope.dc;
if (dc != null) {
return dc.isSorted() ? "Sorted collection" : "Unsorted collection";
}
Parent
A button processing a document collection assigns the NotesDocumentCollection object to a global variable. This computed field queries the global variable and displays the title of the parent database.
var dc:NotesDocumentCollection = sessionScope.dc;
if (dc != null) {
return dc.getParent().getTitle();
}
Query
A button processing a document collection assigns the NotesDocumentCollection object to a global variable. This computed field queries the global variable and displays its query if it is sorted.
var dc:NotesDocumentCollection = requestScope.dc;
if (dc != null) {
return dc.isSorted() ? "Indexed on " + dc.getQuery() : "Unsorted collection";
}
UntilTime
This button gets all documents in the current database modified since the last time the button was clicked.
var profile:NotesDocument = database.getProfileDocument("UntilTimeProfile", null);
if (profile.hasItem("untilTime")) {
var dt:NotesDateTime = profile.getItemValueDateTimeArray("untilTime")[0];
var dc:NotesDocumentCollection = database.getModifiedDocuments(dt);
requestScope.status = "Getting documents since " + dt.getLocalTime();
} else {
var dc:NotesDocumentCollection = database.getModifiedDocuments(null);
requestScope.status = "Getting documents since beginning";
}
profile.replaceItemValue("untilTime", dc.getUntilTime());
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
requestScope.status += "\n" + doc.getItemValueString("subject");
var tmpdoc = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
addDocument
This button merges two collections based on two searches.
var dc:NotesDocumentCollection = database.getAllDocuments();
var dc2:NotesDocumentCollection = dc.cloneCollection();
var query:string = requestScope.query;
var query2:string = requestScope.query2;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
if (!query2.isEmpty()) {
query2 = "\"" + query2 + "\"";
dc2.FTSearch(query2);
var doc2:NotesDocument = dc2.getFirstDocument();
while (doc2 != null) {
// Add document from second query to first if not already there
if (dc.getDocument(doc2) == null) {
dc.addDocument(doc2);
}
var tmpdoc2 = dc2.getNextDocument();
doc2.recycle();
doc2 = tmpdoc2;
}
}
requestScope.status = "Query results:";
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
requestScope.status += "\n" + doc.getItemValueString("subject");
var tmpdoc = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
} else {
requestScope.status = "No query";
}
cloneCollection
This button gets a collection of all documents in the current database and clones it. The first collection is then reduced to one document by a search. That document is used in the cloned collection to get the previous and next documents.
var dc:NotesDocumentCollection = database.getAllDocuments();
var clone:NotesDocumentCollection = dc.cloneCollection();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query, 1);
var doc:NotesDocument = dc.getFirstDocument();
if (doc != null) {
requestScope.status = "";
var doc2:NotesDocument = clone.getDocument(doc);
var doc1:NotesDocument = clone.getPrevDocument();
var doc3:NotesDocument = clone.getNextDocument();
if (doc1 != null) {
requestScope.status +=
"\nPrevious: " + doc1.getItemValueString("subject");
}
if (doc2 != null) {
requestScope.status +=
"\n" + doc2.getItemValueString("subject");
}
if (doc3 != null) {
requestScope.status +=
"\nNext: " + doc3.getItemValueString("subject");
}
} else {
requestScope.status = "No hit"
}
} else {
requestScope.status = "No query"
}
contains
This button determines if the current document is in the collection resulting from a search.
try {
var noteid:string = currentDocument.getDocument().getNoteID();
var dc:NotesDocumentCollection = database.getAllDocuments();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
if (dc.contains(noteid)) {
requestScope.status = "Current document contains query";
} else {
requestScope.status = "Current document does not contain query";
}
} else {
requestScope.status = "No query";
}
} catch(e) {
requestScope.status = e.message;
}
deleteDocument
This button intersects two collections based on two searches.
var dc:NotesDocumentCollection = database.getAllDocuments();
var dc2:NotesDocumentCollection = dc.cloneCollection();
var query:string = requestScope.query;
var query2:string = requestScope.query2;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
if (!query2.isEmpty()) {
query2 = "\"" + query2 + "\"";
dc2.FTSearch(query2);
var doc2:NotesDocument = dc2.getFirstDocument();
while (doc2 != null) {
// Delete document from second query if it is not in first
var tmpdoc2 = dc2.getNextDocument();
if (dc.getDocument(doc2) == null) {
dc2.deleteDocument(doc2);
}
doc2.recycle();
doc2 = tmpdoc2;
}
}
requestScope.status = "Query results:";
var doc:NotesDocument = dc2.getFirstDocument();
while (doc != null) {
requestScope.status += "\n" + doc.getItemValueString("subject");
var tmpdoc = dc2.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
} else {
requestScope.status = "No query";
}
FTSearch
This button gets all the documents that match a user-specified query.
var dc:NotesDocumentCollection = database.getAllDocuments();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query, 16);
if (dc.getCount() > 0) {
requestScope.status = dc.getCount().toFixed() + " hit(s):"
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
requestScope.status += "\n" + doc.getItemValueString("subject");
var tmpdoc = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
} else {
requestScope.status = "No hits"
}
} else {
requestScope.status = "No query"
}
getDocument
This button gets a collection of all documents in the current database and clones it. The first collection is then reduced to one document by a search. That document is used in the cloned collection to get the previous and next documents.
var dc:NotesDocumentCollection = database.getAllDocuments();
var clone:NotesDocumentCollection = dc.cloneCollection();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query, 1);
var doc:NotesDocument = dc.getFirstDocument();
if (doc != null) {
requestScope.status = "";
var doc2:NotesDocument = clone.getDocument(doc);
var doc1:NotesDocument = clone.getPrevDocument();
var doc3:NotesDocument = clone.getNextDocument();
if (doc1 != null) {
requestScope.status +=
"\nPrevious: " + doc1.getItemValueString("subject");
}
if (doc2 != null) {
requestScope.status +=
"\n" + doc2.getItemValueString("subject");
}
if (doc3 != null) {
requestScope.status +=
"\nNext: " + doc3.getItemValueString("subject");
}
} else {
requestScope.status = "No hit"
}
} else {
requestScope.status = "No query"
}
getFirstDocument getNextDocument
This button gets all the documents in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
requestScope.status += "\n" + doc.getItemValueString("subject");
var tmpdoc:NotesDocument = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
This button gets the second document in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
if (dc.getCount() > 1) {
var doc:NotesDocument = dc.getNextDocument(dc.getFirstDocument());
requestScope.status = doc.getItemValueString("subject");
doc.recycle();
}
getLastDocument getPrevDocument
This button gets all the documents in the current database in reverse order.
var dc:NotesDocumentCollection = database.getAllDocuments();
var doc:NotesDocument = dc.getLastDocument();
while (doc != null) {
requestScope.status += "\n" + doc.getItemValueString("subject");
var tmpdoc:NotesDocument = dc.getPrevDocument();
doc.recycle();
doc = tmpdoc;
}
This button gets the next to the last document in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
if (dc.getCount() > 1) {
var doc:NotesDocument = dc.getPrevDocument(dc.getLastDocument());
requestScope.status = doc.getItemValueString("subject");
doc.recycle();
}
getNthDocument
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;
}
markAllRead
This button marks as read documents that match a search query in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
dc.markAllRead();
} else {
requestScope.status = "No query";
}
markAllUnread
This button marks as unread documents that match a search query in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
dc.markAllUnread();
} else {
requestScope.status = "No query";
}
putAllInFolder
This button adds documents that match a search query to a folder in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
dc.putAllInFolder("Search Results", true);
} else {
requestScope.status = "No query";
}
removeAll
The following button creates a document collection, adds documents conditionally, then removes those documents.
var dc:NotesDocumentCollection = database.createDocumentCollection();
var view:NotesView = database.getView("main");
var doc:NotesDocument = view.getFirstDocument();
while (doc != null) {
if (doc.getItemValueString("subject").endsWithIgnoreCase("obsolete")) {
dc.addDocument(doc);
}
doc = view.getNextDocument(doc);
}
requestScope.status = "Number of documents removed: " + dc.getCount();
dc.removeAll(true);
removeAllFromFolder
This button removes documents that match a search query from a folder in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
dc.removeAllFromFolder("Search Results");
} else {
requestScope.status = "No query";
}
stampAll
This button replaces an item value in documents that match a search query in the current database.
var dc:NotesDocumentCollection = database.getAllDocuments();
var query:string = requestScope.query;
if (!query.isEmpty()) {
query = "\"" + query + "\"";
database.updateFTIndex(true);
dc.FTSearch(query);
dc.stampAll("quantity", 15);
} else {
requestScope.status = "No query";
}