Wednesday 13 May 2015

LOTUSSCRIPT: Clear Documents from Trash Folder after SoftDeletion Expiry time (if not cleared in due time)

Scenario:

By default, the Soft Deletion setting “Permanently delete documents after” is set to 48 hours. If someone try to set it to lower value like 1 hour, the mails doesn’t get cleared after 1 hour. instead it remains in Trash folder until updall command is executed on the database.

 image

Issue:

Running “updall” command every hour on mailboxes is not possible, instead a script is required which can perform the same operation.

Workaround:

Following script performs the operation as desired to clear the documents from Trash folder after Soft deletion expiry time. Once deleted, documents are moved to ($SoftDeletions) view.

    Dim s As New NotesSession
    Dim hours As Integer
    Dim db As NotesDatabase
    Dim vw As NotesView
    Dim doc As NotesDocument
    Dim doc2 As NotesDocument
    Set db = s.Currentdatabase
    If db.getoption(dbopt_softdelete) Then
        hours%=db.undeleteexpiretime
        On Error Resume Next
        'MsgBox hours% & " hour(s)"
    End If
    Set vw = db.Getview("($SoftDeletions)")
    Set doc = vw.Getfirstdocument()
    Dim dtDeleteCheck As NotesDateTime
    Set dtDeleteCheck = s.Createdatetime(Now())
    Call dtDeleteCheck.Adjusthour(-1 * hours%)
    Dim dtDeleted As NotesDateTime
    While Not doc Is Nothing
        Set doc2 = vw.Getnextdocument(doc)
        Set dtDeleted = s.Createdatetime(doc.Lastmodified)
        MsgBox "dtDeleteCheck.Timedifference(dtDeleted): " & dtDeleteCheck.Timedifference(dtDeleted)
        If (dtDeleteCheck.Timedifference(dtDeleted) > 0) Then
            MsgBox "Message to be cleared.. " & doc.subject(0) & " : " & doc.Lastmodified
            Call doc.Removepermanently(true)
            'MsgBox doc.subject(0) & " : " & doc.Lastmodified
        Else
            MsgBox "Message NOT TO BE DELETED YET.. " & doc.subject(0) & " : " & doc.Lastmodified
        End If
        Set doc = doc2
    Wend

No comments:

Post a Comment