SNTT : Trapping Document Delete in LotusScript to skip Document processing

This all started because I wanted to skip certain processing on a document if a document was going to be deleted (if it was going to be deleted the process was redundant).

There is a nice DeleteDocument method for the notesUIDocument object which “Marks the current document for deletion and closes it.”, but I needed to know if it had been “Marked for Deletion”. Nothing. No nice notesDocument or notesUIDocument properties to tell me “IF” it has been marked for deletion. Ack!

So I had to invent my own, at least until lotus exposes one! (Hint, Hint! feature request!)

The saving feature here is that the Database Querydocumentdelete event is fired before the Documement QueryClose event.

1
2
3
4
5
6
7
8
9
10
11
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
dim dc as notesdocumentcollection
Set dc = source.documents
dim doc as notesdocument
Set doc = dc.GetFirstDocument
Do While Not doc Is Nothing   ' mark that this document is going to be deleted
doc.MarkedForDeletion = "YES"
Call doc.Save (True,False,False)
Set doc = dc.GetNextDocument(doc)
Loop
end sub

I also coded up the Database Querydocumentundelete event in case that the document gets unmarked for deletion before it actually get deleted so the desired process of the document will happen next time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Sub Querydocumentundelete(Source As Notesuidatabase, Continue As Variant)
dim dc as notesdocumentcollection
Set dc = source.documents
dim doc as notesdocument
Set doc = dc.GetFirstDocument
While Not(doc Is Nothing)
If Doc.HasItem("MARKEDFORDELETION") Then
' the MARKEDFORDELETION item is set in the Database Querydocumentdelete event
doc.RemoveItem("MARKEDFORDELETION") ' this is no longer being deleted so the remove the mark
Call doc.Save(True,False,True)
End If
Set doc = dc.getnextdocument(doc)
Wend
end sub

And then with all the setup work done I check in the Documents Queryclose event whether the documents is about to be deleted.

1
2
3
4
5
6
7
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
If Source.document.HasItem("MARKEDFORDELETION") Then
' the MARKEDFORDELETION item is set in the Database Querydocumentdelete event
Exit Sub
End If
'otherwise do you whatever you would usually do
exit sub

If you wanted to only trap the delete that happens within the document, but not from the view then in the Querydocumentdelete event you would look to see if “workspace.CurrentView is Nothing” is true.

I previously bloged on a related subject :

Happy deleting…. (technorati.com tags :, )

One Reply to “SNTT : Trapping Document Delete in LotusScript to skip Document processing”

  1. this is IMO bad technique – every time user tags documents for deletion (remember – he can untag them also) the document is resaved. risks? replication conflicts. you may say – I dont mind, document is going to be deleted, anyway. but who will delete conflict? another risk: replication bandwidth, especially for large amounts of docs.

    hint: did you try to create ($Trash) folder and query the docs there? I think documents marked for deletion are there.

Leave a Reply