Delete the Open Document and Delete the Currently Selected Documents

Mindwatering Incorporated

Author: Tripp W Black

Created: 01/30/2013 at 06:49 PM

 

Category:
Notes Developer Tips
Actions, Formulas, LotusScript

Objective:
Provide a delete button @Formula code on a form for an open document, including an are-you-sure dialog:

Solution:
tmpvar:= @Prompt([YesNo]; "Delete?"; "Are you sure you want to delete this document? You cannot undo this choice.");
@If(tmpvar=1; @Do(@Command([MoveToTrash]); @Command([EmptyTrash])); @Return(""))


Objective:
Provide a Delete Button to delete selected documents in the current view, including an are-you-sure dialog:

Sub Click(Source As Button)
Dim w As New NotesUIWorkspace
Dim s As New NotesSession
Dim uiDb As NotesUIDatabase
Dim uiV As NotesUIView
Dim db As NotesDatabase
Dim col As NotesDocumentCollection ' selected doc(s) to be deleted
Dim cDoc As NotesDocument ' current doc in col to be deleted
Dim cNxtDoc As NotesDocument ' doc after cDoc
Dim askme As Integer ' are-you-sure nag prompt
Dim asktitle As String ' title for prompt
Dim askmsg As String ' message body for prompt

Set uiDb = w.CurrentDatabase
Set db = s.CurrentDatabase
Set col = db.UnprocessedDocuments
Set uiV = w.CurrentView

If Not (col.Count = 0) Then
' have documents selected. confirm first
If (col.Count>1) Then
asktitle = "Delete Selected Documents?"
askmsg = "You have " & Cstr(col.Count) & " documents selected. Are you sure you want to delete them?"
Else
asktitle = "Delete Selected Document?"
askmsg = "Are you sure you want to delete the document you have currently selected?"
End If
askme = w.Prompt (PROMPT_YESNO, asktitle, askmsg)
If askme = 1 Then
' delete document(s)
Set cDoc = col.GetFirstDocument()
While Not (cDoc Is Nothing)
' get next doc while key doc still exists
Set cNxtDoc = col.GetNextDocument(cDoc)
Call s.UpdateProcessedDoc(cDoc)
' delete doc
Call cDoc.Remove(True)
' loop
Set cDoc = cNxtDoc
Wend
' refresh view
Call w.ViewRefresh() ' needed or docs won't disappear until manual refresh
Call uiV.DeselectAll() ' otherwise the stubs are still selected!
End If

Else
' no documents selected, look for current document
Msgbox "No documents were selected. Please select one or more to delete and try again.",, "Aborted Deletion"
End If


End Sub


previous page