Domino Code Fragment

Code Name*
Preventing Orphan Responses
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.141.24.134
Description*
When you delete a main document, its response documents are not automatically deleted They become "orphan response" documents. To prevent users from creating orphan responses, have the database object's Querydocumentdelete event trigger the following script:
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)

Dim workspace As NotesUIWorkspace
Dim documents, responses As NotesDocumentCollection
Dim doc As NotesDocument, nextdoc As NotesDocument, responsedoc As NotesDocument
Dim allowed As Variant, condition As Variant
Dim choice As Integer, boxtype As Integer


' Defined constants here because I can't include LSCONST.LSS.
Const MB_YESNO = 4
Const MB_ICONQUESTION = 32
Const MB_DEFBUTTON2 = 256
Const MB_APPLMODAL = 0
Const IDYES = 6


' The script will delete the document if allowed
Continue = False


' Warn user that Del key works differently than expected
boxtype = MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2 + MB_APPLMODAL
choice = Messagebox( "This will immediately and permanently delete the selected document and its responses. Continue?", boxtype, "Delete
Document" )
If Not ( choice = IDYES ) Then
Print "Deletion cancelled at user's request"
Exit Sub
End If


Set documents = Source.Documents
Set doc = documents.GetFirstDocument
While Not ( doc Is Nothing )
Set nextdoc = documents.GetNextDocument( doc )
allowed = False
' NOTE: Change the following statement so that condition is True if the user is allowed to delete the doc, False otherwise.
condition = True
If ( condition ) Then
allowed = True
End If
' Delete responses to current document
If ( allowed ) Then
Set responses = doc.Responses
Set responsedoc = responses.GetFirstDocument
While Not ( responsedoc Is Nothing )
Call responsedoc.Remove( True )
Wend
Else
Messagebox "You are not authorized to delete document " & doc.NoteID
' NOTE: You'll probably want to use something other than the NoteID, such as the Subject, to identify the document.
End If
' Delete the main document
If ( allowed ) Then
Call doc.Remove( True )
End If
Set doc = nextdoc
Wend


' Refresh the current view
Set workspace = New NotesUIWorkspace
Call workspace.ViewRefresh()


End Sub