Search code examples
xpageslotus-dominolotusscriptxpages-ssjs

remove document from notesdocumentcollection


I want to remove all documents from a database except 1, the configuration document. I have the following ssjs code:

var dc:NotesDocumentCollection = database.getAllDocuments();
var vw:NotesView = database.getView("configuration");
var doc:NotesDocument = vw.getFirstDocument();
if (dc.getCount() > 0){
    if (doc != null){
        dc.deleteDocument(doc);
    }
    dc.removeAll(false);
}

however when I run the script I get an error on command dc.deleteDocument(doc);

What am I doing incorrect?


Solution

  • Use

         dc.subtract(doc);
    

    instead of deleteDocument(). This is the recommended way to remove a document from a collection.