• How to log doc deletions

    By Doug Finner 2 decades ago

    I want to log deletions of documents, not attempted deletions, actual 'it's gone, buh bye' deletions.



    I created the agent below.

    If I build a trigger to run this agent before a doc is deleted, the doc ID is all zeros and the doc fields are null.

    If I build the trigger to run this agent after a doc is deleted, I get the doc id but the doc fields are still null.



    Since the intent of this agent is to keep track of doc deletions, the doc ID isn't much use; I need some kind of human friendly doc identifier and I need to be able to snag data from the doc.



    What am I missing?



    TIA



    Doug



    Sub Initialize

    Dim session As New NotesSession <br/>
    Dim MsgString As String<br/>
    <br/>
    MsgString = &quot;Doc with ID: &quot; &amp; session.DocumentContext.UniversalID &amp;_<br/>
    &quot; Form: &quot; &amp; session.DocumentContext.form(0) &amp; _<br/>
    &quot; Identifier: &quot; &amp; session.DocumentContext.ClassName(0) &amp; _<br/>
    &quot; was deleted on: &quot; &amp; Cstr(Now) &amp; _<br/>
    &quot; by: &quot; &amp; session.CommonUserName<br/>
    <br/>
    Print MsgString  <br/>
    

    End Sub



    Db is currently local, I'll be doing this on server dbs once I figure out how it all works.



    Follow up 09.Feb.2010

    I have been away from this for a while but have been playing the last 2 days.



    You need to run the agent after deletion.

    You can access the properties for the deleted doc (UNID, create date).

    You cannot access any fields within the doc. Doesn't seem to matter how you go at it, items don't exist.



    I tried modifying the default 'log changes' agent to turn it into a 'log deletions'; I removed all code that executes for the 'pre' event and passed in only the newDoc value to the function that logs changes.



    I'm sure I'm missing something obvious. This would be a great feature if I could figure out how to make it work.



    23.Feb.2010 - additional information.

    The reason the post-event doesn't work is because the 'before' document is now just a stub and only some doc properties are available.

    It's not clear why the pre-event doesn't allow capture of the doc and its properties.