Problem With QueryDocumentDelete

Discussion in 'Lotus Notes General Discussion' started by Iain Wilson, May 27, 2004.

  1. Iain Wilson

    Iain Wilson Guest

    Hi All

    Can someone please help.
    I have the following piece of code in the QueryDocumentDelete event

    This is supposed to record details of all document deletions (There
    are very
    few and this will not grow in size very quickly).

    The process works well in that when I delete any document a form
    FormDelete is created with some basic details recording who, when and
    some of the key fields from the document being deleted.

    I have created a view so that these tracking (or trace) documents can
    be viewed by all users.

    I want to stop anyone from deleting these tracking documents so that
    we have a history of what has been deleted.

    The section of code

    If Doc.HasItem("Form") Then
    If Doc.GetItemValue("Form")(0) = "FormDelete" Then
    Contiune = False
    Else
    .............
    .............

    works well and does not allow deletion the document when the delete
    button is pressed.

    However, after this piece of code has been executed the document is
    'Marked For Deletion'. If the user then presses F9 the document is
    deleted.


    Is there any way I can disable F9 is this view ?

    Any suggestions would be most welcome

    Thanks in advance

    Iain


    ---------------------------------------------------------------------------
    Dim db As NotesDatabase
    Dim session As New NotesSession
    Dim username As String
    Dim item As NotesItem
    Dim nnUser As NotesName
    Dim doc As NotesDocument
    Dim Deletion As NotesDocument
    Dim dc As NotesDocumentCollection
    Dim LDocument As String
    Dim LToday As NotesDateTime
    Dim LStoday As String
    Dim LProduct_Line As String
    Dim LProduct As String
    Dim LOpName As String
    Dim LOpStatus As String
    Dim LForm As String
    Dim LModel As String

    Set LToday = New NotesDateTime("Today")
    Set db = session.CurrentDatabase
    Set Session = New NotesSession
    username = session.CommonUserName
    Set dc = Source.Documents

    Print dc.count
    For b = 1 To dc.Count
    Set doc = dc.GetNthDocument( b )
    If Doc.HasItem("Form") Then
    If Doc.GetItemValue("Form")(0) = "FormDelete" Then
    Contiune = False
    Else
    Set Deletion = db.CreateDocument
    LProduct_Line = ""
    LProduct = ""
    LOpName = ""
    LOpStatus = ""
    LModel = ""

    If Doc.HasItem("Form") Then
    Deletion.FormDeleted = doc.GetItemValue("Form")(0)
    LForm = doc.GetItemValue("Form")(0)
    End If
    If Doc.HasItem("ProductLine") Then
    LProductLine = Doc.GetItemValue("ProductLine")(0)
    End If
    If Doc.HasItem("Product") Then
    LProduct = Doc.GetItemValue("Product")(0)
    End If
    If Doc.HasItem("Model") Then
    LModel = Doc.GetItemValue("Model")(0)
    End If
    If Doc.HasItem("OpName") Then
    LOption = Doc.GetItemValue("OpName")(0)
    End If
    If Doc.HasItem("OpStatus") Then
    LOpStatus = Doc.GetItemValue("Status")(0)
    End If

    Deletion.DeletedBy = Username
    Deletion.Form = "FormDelete"
    LStoday = Cstr(LToday.DateOnly)
    Deletion.WhenDeleted = LSToday

    Deletion.DeletionHistory = "Form " & LForm & " Was Deleted By " &
    UserName & " On " & LSToday & ". Product Line = " & _
    LProductLine & ". Product = " & LProduct & ". Model = " & LModel &
    ". Option = " & LOption & ". Option Status = " & LOpStatus

    Continue = True

    Call Deletion.Save(False, False)
    End If
    End If
    Next
    ---------------------------------------------------------------------------
     
    Iain Wilson, May 27, 2004
    #1
    1. Advertisements

  2. Iain Wilson

    Joachim Nock Guest

    Hi Iain,
    Setting Continue to False doesn't do anything since the loop will
    continue anyway. The next document of the collection which gets recorded
    resets Continue to True so your code will only work if there are only
    "FormDelete" - documents in the collection. The Continue flag will not
    be evaluated until the complete event is processed. You could jump out
    of the event by the first "FormDelete" document but that wouldn't
    process the other documents in the collection.

    Problem is that you are checking a complete collection of documents
    where some shall not be deleted while others shall be recorded and
    deleted. That's tricky...

    If the collection contains FormDelete documents as well as normal
    documents you'll have a problem. Since you can only pass or fail the
    complete event with all documents, its not possible to react on a single
    document. I'd suggest another approach: Remove all "FormDelete"
    documents from the collection and delete the remainig collection
    documents while you are still in the event. Then leave the event with
    continue = False and everything should be fine. Maybe you need to
    refresh the view afterwards. Only drawback: The documents get deleted at
    once and not marked for deletion. I've no idea right now on how to
    deselect or select the deletion flags.

    I rewrote your code since it was hard for me to understand it with all
    the field checks (which are not required). It's a bit shorter now:

    Dim db As NotesDatabase
    Dim session As New NotesSession
    Dim username As String
    Dim doc As NotesDocument
    Dim deletion As NotesDocument
    Dim dc As NotesDocumentCollection
    Dim LToday as NotesDateTime

    Set LToday = New NotesDateTime(Today)
    Set db = session.CurrentDatabase

    Set dc = Source.Documents
    Print dc.count

    Set doc = dc.GetFirstDocument
    if doc.Form(0) <> "FormDelete" then 'skip FormDelete documents
    set deletion = New NotesDocument(db)
    deletion.FormDeleted = doc.Form(0)
    deletion.DeletedBy = session.CommonUsername
    deletion.Form = "FormDelete"
    deletion.WhenDeleted = Cstr(LToday.DateOnly)
    deletion.DeletionHistory = "Form " & doc.Form(0) &_
    " Was Deleted By " & deletion.DeletedBy(0) &_
    " On " & deletion.WhenDeleted(0) &_
    ". Product Line = " & doc.LProductLine(0) &_
    ". Product = " & doc.LProduct(0) &_
    ". Model = " & doc.LModel(0) &_
    ". Option = " & doc.LOption(0) &_
    ". Option Status = " & doc.LOpStatus(0)
    Call deletion.Save(True, True)
    End If

    set doc = dc.GetNextDocument(doc)
     
    Joachim Nock, May 27, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.