Thursday, April 20, 2006

Who Deleted That Document? (SnTT)

Ever have a problem with someone deleting data that should not have been deleted? Of course you should lock down the ACL, but what if you just want to track deletions in a database? Or possibly you want to prompt someone for a reason they deleted the document? While there is no native Domino log to display this, you can utilize the Database Script to get a handle on deletions.

This is how I have accomplished this task for various reasons. After looking through the Designer Help database and creating a log database, use the following code in the Querydocumentdelete sub of the Database Script. Also, you can grab as much data from as many fields as you would like. Further, you could implement a prompt for each document (inside the loop) or all documents (outside the loop) to have input for why the document was deleted.

Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)

Dim docsDelete As NotesDocumentCollection
Dim doc As NotesDocument
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Set docsDelete = Source.Documents ' Docs chosen for deletion

Dim delLog As New NotesLog(db.FilePath)
For x = 1 To docsDelete.Count
Set doc = docsDelete.GetNthDocument( x )
Call delLog.OpenNotesLog("SERVERNAME", "pathname\loggingdb.nsf")
Call delLog.LogAction("The following user was deleted by " + session.CommonUserName + ": " + Cstr(doc.FirstName(0)) + " " + doc.LastName(0))
Call delLog.Close

'The following section emails a notification of the deletion
Dim maildb As NotesDatabase
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set maildb = session.CurrentDatabase
Set maildoc = New NotesDocument( maildb )
Set rtitem = New NotesRichTextItem( maildoc, "Body" )
Call rtitem.AppendText ("The following user was deleted by " + session.CommonUserName + ": " + Cstr(doc.FirstName(0)) + " " + doc.LastName(0))
maildoc.Form = "Memo"
maildoc.SendTo = "Recipient"
maildoc.Subject = "Intranet Directory Document Deleted"
Call maildoc.Send( True )

Next
Continue = True

End Sub
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.


And here is a sample of what the logging database can look like as a single repository for tracking multiple databases:



No comments: