Link to home
Start Free TrialLog in
Avatar of marcule
marcule

asked on

recursivelly marking responses for deletion

Hi,

I have developed a database handling hierarchy of documents and their responses. I am trying to write a recursive database script for that when I delete a document in a view, all other response documents are marked for deletion too (but not directly removed !). The only way to mark for deletion a document seems to be the @command([MoveToTrash]) which marks the currently selected doc in the current view (and its equivalent [EditClear]). The other possibilities permanently delete documents (e.g. notesDocument.Remove True). So i have written the following RecursiveDelete database script :

Sub RecursiveDelete(doc As NotesDocument)
     'This script is a DFS-like search on the doc entry responses
        Dim childrens As NotesDocumentCollection
     Dim child As NotesDocument    
     Dim nextChild NotesDocument
     Dim workspace As New NotesUIWorkspace
     
     Set childrens = doc.Responses
     Set child = childrens.GetFirstDocument
     
     While Not child Is Nothing
          Set nextChild = childrens.GetNextDocument (child)
          RecursiveDelete  child
          Set child = childNext
     Wend
     
     'Select the document ant mark it to deletion
        'This happens first on the last level of the
        'hierarchy, because we are dooing a DFS
        workspace.CurrentView.SelectDocument(doc)    
     Evaluate("@Command([MoveToTrash])")
End Sub

I call this script in the QueryDocumentDelete like this (for making things easier, i suppose that a single doc is selected for deletion; if not, one have to do the following for the entire collection source.Documents)

Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
     Dim doc As NotesDocument    
     
     Set doc = source.Documents.GetFirstDocument
     Call RecursiveDelete( doc )          
End Sub

This goes down in the hierarchy, selects each children of the document...but doesn't mark it for deletion. At the end, only the initial document which raised the event is marked for deletion.

Somebody could help me understand why and/or give me a solution to my problem ?

Thanks
Avatar of scottrma
scottrma

Perhaps should this line:

Set child = childNext

instead be:

Set child = nextChild

Regards,

Scott
Avatar of marcule

ASKER

hi Scott

It would be too easy :)

After a copy-paste from my database script I changed childNext into nextChild, but I forgot to put it in the Set child statement. Sorry about this mistake

Andrei
I suspect perhaps the @Command is causing problems in this context. To verify whether this is the case or not, try either commenting out this line:

Evaluate("@Command([MoveToTrash])")

or changing it to something like:

Evaluate("@True")

and then try deleting a document and see if all the responses get selected or not. If they do, then the problem is with that statement. Some @Commands have problems running in a repeated or recursive context, that is the reason why there is a Notes agent type called "Run Once (@Commands may be used)", I am sure you have probably seen this in Designer. Those @Commands can only be used if your code is running in the context of a single document. I am not sure if this is the case here or not, thus the reason why I suggested to try commenting out this line and test the code out to see what happens.

Regards,

Scott
Avatar of marcule

ASKER

I found in the Notes help that Evaluate doesn't work with @Commands...so you are right. Evaluate causes the problem.

If I comment the Evaluate statement, nothing special happens. It's just like before, only the root document is marked for deletion.

So what I need is another way for marking the currently selected doc for deletion. Does this exists ?

Thank you for your comments,

Andrei
ASKER CERTIFIED SOLUTION
Avatar of scottrma
scottrma

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of marcule

ASKER

Hi Scott,

I only had to do one-two little tricks except for your ideea. Here goes...

The problem with the notesUIDocument.DeleteDocument is that a call to this method implies the occurence of the Querydocumentdelete event. So when I used your code, an infinit recursion happened and Lotus...went boom (stack overflow :-).
I added a hidden text field in the document's form IsMarkedDeleted, which I set to something different from the empty string before calling DocumentDelete. In the QueryDocumentDelete I test if the value of this document is "". In such is not the case I do nothing.

I even didn't notice the open and close of the windows when docs are temporary opened.

By default, the DocumentDelete closes the current uiDoc and opens the next one in the view. So in the Postdocumentdelete I have to close the current uiDoc of the workspace (which is opened after the last DocumentDelete).

After doing so, all works fine.

Thanks a lot for your help,

Andrei
Glad to be of help and I must say those were some very creative tricks you used to get around the side-effects. Nice!

Regards,

Scott