Eric Forte 3.May.12 03:52 PM a Web browser Domino Designer6.5.6Windows XP
I didn't know that if a document was a soft deletion it would still show up in collections, like the responses collection or the "AllDocuments" collection of NotesDatabase.
Here's a sample script that you can import into an agent. It shows a few simple NotesAPI-based calls that you can use to determine if a document is a soft deletion or not.
I hope this saves somebody a few hours!
Enjoy!
Eric Forte
@ericnforte
=================
Option Public
Option Explicit
Declare Private Function W32_NSFNoteOpen Lib "nnotes" Alias "NSFNoteOpen" (Byval hdb As Long, Byval NoteID As Long, Byval OpenFlags As Integer, lnghNote As Long) As Integer
Declare Private Function W32_NSFNoteOpenSoftDelete Lib "nnotes" Alias "NSFNoteOpenSoftDelete" (Byval hdb As Long, Byval NoteID As Long, Byval OpenFlags As Integer, lnghNote As Long) As Integer
Declare Private Function W32_NSFDbOpen Lib "nnotes" Alias "NSFDbOpen" (Byval PathName As String, rethDB As Long) As Integer
Declare Private Function W32_NSFDbClose Lib "nnotes" Alias "NSFDbClose" (Byval hDB As Long) As Integer
Declare Private Function W32_NSFNoteClose Lib "nnotes" Alias "NSFNoteClose" (Byval note_handle As Long) As Integer
Function isSoftDeletion(doc As NotesDocument, hdb As Long) As Boolean
%REM
If you can open the note with NSFNoteOpen, then it's not a soft deletion. If you cannot, but can then open it with
NSFNoteOpenSoftDelete, then it is a soft deletion.
Of course, you would probably want to test to make sure the document passed in is not "Nothing" before trying this.
%END REM
Dim hNote As Long
Dim rc As Integer
rc = W32_NSFNoteOpen(hdb, Val("&h" & doc.NoteID), 0, hNote)
If rc = 0 Then
'Not a soft deletion
W32_NSFNoteClose hNote
Else
rc = W32_NSFNoteOpenSoftDelete(hdb, Val("&h" & doc.NoteID), 0, hNote)
If rc = 0 Then
isSoftDeletion = True
W32_NSFNoteClose hNote
End If
End If
End Function
Function getAPIDbHandle(db As NotesDatabase) As Long
Dim hdb As Long
Dim rc As Integer
If db.Server = "" Then
rc = W32_NSFDbOpen(db.FileName, hDb)
Else
rc = W32_NSFDbOpen(db.Server & "!!" & db.FileName, hDb)
End If
If rc = 0 Then
getAPIDbHandle = hDb
Else
getAPIDbHandle = 0
End If
End Function
Sub Initialize
%REM
This was written with Lotus Notes 6.5 in mind. Documents that are soft deletions, among other things, still show up in collections, like
the "Responses" collection. You can't really use the NotesAPI function NSFSearch from within LotusScript because of the need to
provide a callback function.
However, you can pass a NoteID to NSFNoteOpen, then NSFOpenSoftDeletion to see if it is a soft deletion (see function isSoftDeletion)
Enjoy!
3-May-2012 - Eric Forte
@ericnforte
%END REM
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim hDb As Long
Set db = s.CurrentDatabase
hDb = getAPIDbHandle(db)
If hDb = 0 Then
'Error getting db handle
Exit Sub
End If
Set dc = db.AllDocuments
Set doc = dc.GetFirstDocument
While Not doc Is Nothing
If isSoftDeletion(doc, hDb) Then
Print "Doc is soft deletion"
Else
Print "Doc is not soft deletion"
End If