Thursday, June 10, 2010

deleteCollectionWithDescendents in Lotusscript

Function deleteCollectionWithDescendents(inputDocCol As NotesDocumentCollection ) As Boolean
'******************************************************************
'@Created : 10-Jun-2010
'@Author : Karthikeyan A
'@Purpose: To delete documents in a collection along with their descendents
'@Type : Function
'@Name : deleteCollectionWithDesendents
'@Param : inputDocCol - the collection of documents which must be deleted along with descendents
'@Return : Boolean- true if operation suceeds and false other wise
'******************************************************************
'mark the flow of control getting inside the current function
deleteCollectionWithDescendents=False

'declare all variables and objects necessary for further manipulation
Dim resDocCol As NotesDocumentCollection
Dim doc As NotesDocument
Dim tempDoc As NotesDocument

'handle errors in case of abrupt termination
On Error Goto errHandler

'if there are no documents found in the collection then exit function
If inputDocCol.Count=0 Then Exit Function
'get the first document in the collection
Set doc=inputDocCol.GetFirstDocument()
'loop and delete the document along with its descendents untill no more selected documents exist
While Not doc Is Nothing
'get the collection of the responses of the current doc of interest
Set resDocCol=doc.Responses
'reinitiate the process with this collection as the input - recursion
Call deleteCollectionWithDescendents(resDocCol)
'once all the descendents are removed, remove the parent (current document of interest)
Set tempDoc=doc
'set the handle for the next document in the collection
Set doc=inputDocCol.GetNextDocument(doc)
Call tempDoc.Remove(True)
Wend

'mark the flow of control moving out of the current function
deleteCollectionWithDescendents=True
Exit Function
'inform the user about the error that resulted in abrupt termination
errHandler:
Msgbox "Error: ***" & Error & "*** encountered on line *** " & Cstr(Erl) & " *** with error number *** " _
& Cstr(Err) & " *** in function deleteCollectionWithDescendents"
End Function

No comments:

Post a Comment