Domino Code Fragment

Code Name*
QueryDocumentDelete script to prevent deletion of a document marked as Permanent
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.19.27.178
Description*
After I accidentally deleted an important document in one of our databases, I wrote this
little script to prevent it from happening again. This script will disable deletion of
any document (even by managers)marked as "Permanent" in a keyword, checkbox field on the
document form. This agent runs in the QueryDocummentDelete event of the database.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)

'Delcare the database and document(s) this agent is working on
Dim uidb As notesUIdatabase
Dim collection As notesdocumentcollection
Dim doc As Notesdocument


'NotesUIDatabase class is only accessible as a source parameter
Set uidb = source


'Get to the document(s) selected for deletion
Set collection = uidb.documents
Set doc = collection.GetFirstDocument


'Walk through the document collection.
Do
'If any documents are marked as "Permanent" in the DeleteStatus field, warn the user and stop the deletion
If doc.DeleteStatus(0) = "Permanent" Then
'Tell the user they cannot delete the document
Messagebox "The document entitled" & Chr(13) & Chr(13) & doc.Subject(0) _
& Chr(13) & Chr(13) & " is marked as Permament and cannot be deleted!", 16, "Stop!"
'Stop execution of the delete process
Continue = False
'Bail out of the program if a document is marked as "Permanent"
Exit Sub
End If
'Otherwise, get the next document in the collection
Set doc=collection.GetNextdocument(doc)
'Go through the process of checking for a "Permanent" document until there are no document(s) left
Loop Until doc Is Nothing


End Sub