Thursday, August 5, 2010

Delete Documents from a View - A Simple Generic Function in Lotusscript


Function deleteSelectedDocuments As Boolean
'***********************************************************
'@Purpose : To delete all the selected documents from a view
'@Author   : Karthikeyan A
'***********************************************************
'mark the flow of control getting inside the current function
deleteSelectedDocumentsv=False
     'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim database As NotesDatabase
Dim documentCollection As NotesDocumentCollection
Dim userChoice As Integer
'handle errors in case of abrupt termination
On Error Goto errHandler
'set the handle for the current database
Set database=session.CurrentDatabase
'set the handle for the selected documents
Set documentCollection=database.UnprocessedDocuments
'if no documents are selected then inform the same to the user and exit
If documentCollection.Count=0 Then
Msgbox "You have not selected any documents. Please choose some to delete em",,"No documents selected"
Else 
'if user has selected a few documents then ask his confirmation before deleting the same
userChoice=Msgbox ("Do you want to delete " & Cstr(documentCollection.Count) & " document(s)?",64+100, _
"Please confirm...")
'if the user confirms then delete the documents
If userChoice=6 Then
Call documentCollection.RemoveAll(True)
Call workspace.ViewRefresh
End If
End If
'mark the flow of control moving out of  the current function
deleteSelectedDocumentsv=True
Exit Function
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to delete selected documents"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to delete selected documents"
Exit Function
End Function

No comments:

Post a Comment