This tip is an easy method to ask an user for confirmation before deleting any document in a Domino Web application. There is no straightforward way to ask for confirmation and delete the marked documents only from a view for applications on the Web. Hence, use a JavaScript confirmation box in the delete action. Update a field, say, DeleteConfirm field on the form to "yes" or "no". "Yes", if user presses "OK" on the confirmation box. "No" otherwise.
In the view, write the selection formula to include only those documents where DeleteConfirm field is not marked to "Yes". Run a scheduled agent on a view that that selects all the documents marked with DeleteConfirm field as "Yes" and use RemoveAll method to delete them.
Delete Documents agent:
Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Set db = Session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView("DeleteDocuments")
Call view.Refresh
Dim collection As NotesDocumentcollection
Set collection = view.GetAlldocumentsbykey("Yes",True)
Call collection.RemoveAll(False)
End Sub
Javascript for Delete Action button:
if (confirm("Are you sure you want to permanently delete this document?"))
{
alert("This document has been Deleted");
document.forms[0].DeleteConfirm.value = "Yes";
window.document.forms[0].submit();
}
else {
alert("This document is not being Deleted");
document.forms[0].DeleteConfirm.value = "No";
}
This was first published in March 2001