addDocument (NotesDocumentCollection - JavaScript)

Adds a document to a collection.

Defined in

NotesDocumentCollection

Syntax

addDocument(doc:NotesDocument) : void

addDocument(doc:NotesDocument, checkDups:boolean) : void

Parameter Description
doc The document to be added. Cannot be null.
checkDups If true, forces a remote (IIOP) add to be made immediately rather than on the next navigation or other method (such as stampAll) that calls the server, so that a duplicate exception can be thrown immediately. Has no effect on local calls.

Usage

This method throws an exception if:
  • The document is a duplicate of one already in the collection.
  • The document collection is the result of a multi-database full-text search.

Examples

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";
}