Domino Code Fragment

Code Name*
QueryDocumentDelete Event. When a document is selected for deletion delete all response and response to response documents as well.
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.119.139.50
Description*
If a document selected for deletion has response it warns the user that those will also be deleted. It then pushes all response documents and response to response into a delete folder.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
This folder must exist and show responses in hierachy delected. It then walks the collection and removes those as well.
Files/Graphics attachments (if applicable): Code:
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Set db = session.CurrentDatabase
    Dim view As NotesView
    Dim documents As notesdocumentcollection
    Dim doc As NotesDocument
    Dim nextdoc As notesdocument
    Dim foldername As String
    Dim answer As Integer
    Continue = False
    Set documents = Source.Documents
    Set doc = documents.GetFirstDocument
    foldername = "Delete"  
    answer = Messagebox("Delete works differently than expected all responses will be deleted as well, Do you want to continue", 20,  "Warning deleting main and responses?")
    If answer = 6 Then
         While Not ( doc Is Nothing )
              Call doc.PutInFolder( foldername )
              Call PutAllResponsesInFolder( doc, foldername )
              Set doc = documents.GetNextDocument( doc )        
         Wend
    Else          
         Exit Sub
    End If
   
    Set view = db.GetView( folderName )    

     Set doc = view.GetFirstDocument
    Set nextdoc = view.GetNextDocument( doc )
    While Not ( doc Is Nothing )
         Call doc.Remove( True )
         While Not (nextdoc Is Nothing)
              Set doc = nextdoc
              Set nextdoc = view.GetNextDocument( Nextdoc )
              Call doc.Remove( True )
         Wend
    Wend    
   
End Sub


Sub PutAllResponsesInFolder( doc As NotesDocument, folderName As String )
    Dim collection As NotesDocumentCollection
    Dim currentResponse As NotesDocument
    Set collection = doc.Responses
    Set currentResponse = collection.GetFirstDocument
 ' Put immediate responses to doc into the folder
 ' If there are none, sub exits and returns to calling sub
    While Not ( currentResponse Is Nothing )
         Call currentResponse.PutInFolder( folderName )
   ' Recursive call to put immediate responses to
   ' currentResponse in folder
         Call PutAllResponsesInFolder( currentResponse, folderName )
         Set currentResponse = collection.GetNextDocument ( currentResponse )
    Wend
End Sub