Tip

Deleting Documents

The company which I'm working wanted to delete the documents created using
certain forms and to some users. The users may have access from author to
manager. One way I can do is to write a script in database delete, post delete
and undelete event. But I wanted to simplify the process and to give more
flexibility. I wanted programmatic access for deleting and recovering documents
by user without developer's or administrators intervention. I came up with the
following method and hope it helps you all.
Follow the steps to understand deletion, permanent removal from database and
recovery from accidental deletion.


1. Create a button in view call it as "Delete" and enter the following script
in the click event. All the deleted documents are moved to a Folder called
"DeleteFolder". So, create a folder by name "DeleteFolder" and give access to
authorised people to see the deleted documents and recovery options for
accidental delete.

Sub Click(Source As Button)
Dim oUiWs As New NotesUiWorkspace
Dim oSession As New notessession
Dim oDb As NotesDatabase
Dim oDc As NotesDocumentCollection
Dim oDoc As NotesDocument

Set oDb = oSession.CurrentDatabase
Set oDc = oDb.UnProcessedDocuments
i = 1
If (Not oDc Is Nothing) Then
If oDc.Count > 0 Then
Set oDoc = oDc.GetNthDocument(i)
Do While (Not oDoc Is Nothing)
oDoc.Fc_cDeleteDoc = "1"
oDoc.Fc_tDeleteDate = Now
Call oDoc.Save(True,False)
Call oDoc.PutInFolder("DeleteFolder" )
i = i + 1
Set oDoc = oDc.GetNthDocument(i)
Loop
End If
End If
Call oUiWs.ViewRefresh
End Sub

2. In your view, you got to add this selection criteria.
Select "YourSelectionCriteria" and Fc_cDeleteDoc != "1"

3. Create a scheduled agent(runs daily) to remove the document permanently from
the database when the deleted document is older than let's say 7 days. You can
check with the Fc_cDeleteDate field.

4. To recover from accidental delete, create a button in "DeleteFolder" called
"Recover" and enter the following script.

Sub Click(Source As Button)
Dim oUiWs As New NotesUiWorkspace
Dim oSession As New notessession
Dim oDb As NotesDatabase
Dim oDc As NotesDocumentCollection
Dim oDoc As NotesDocument

Set oDb = oSession.CurrentDatabase
Set oDc = oDb.UnProcessedDocuments
i = 1
If (Not oDc Is Nothing) Then
If oDc.Count > 0 Then
Set oDoc = oDc.GetNthDocument(i)
Do While (Not oDoc Is Nothing)
oDoc.Fc_cDeleteDoc = ""
oDoc.Fc_tDeleteDate = ""
Call oDoc.Save(True,False)
Call oDoc.RemoveFromFolder("DeleteFolder" )
i = i + 1
Set oDoc = oDc.GetNthDocument(i)
Loop
End If
End If
Call oUiWs.ViewRefresh
End Sub


Following are the few advantages when you use this method to delete and recover
the documents

a. Option to delete documents created using specific forms - in your view
include the delete button to delete the documents
2. Permission for selected user to delete the document - set the names/roles in
hide/when property of Delete button
3. Don't want to write long scripts in database delete and undelete event - you
can put the scripts in "Delete" and "Recover" button to a script library so
that you don't have to write the same script in each and every view.
4. Want to recover accidental deletion - All the deleted documents will be
moved to "DeleteFolder" where you've an option to recover the documents
5. Option for deleting documents irrespective of user access rights - by this
method, user having author or manager access can delete the document. but using
readers and authors field you can restrict this access.

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.