?
Solved

recursivelly marking responses for deletion

Posted on 2003-04-01
7
Medium Priority
?
425 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:marcule
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:scottrma
ID: 8248836
Perhaps should this line:

Set child = childNext

instead be:

Set child = nextChild

Regards,

Scott
0
 

Author Comment

by:marcule
ID: 8252029
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
0
 
LVL 7

Expert Comment

by:scottrma
ID: 8256076
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:marcule
ID: 8259417
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
0
 
LVL 7

Accepted Solution

by:
scottrma earned 150 total points
ID: 8262805
Try this:

Sub RecursiveDelete(doc As NotesDocument)
    Dim childrens As NotesDocumentCollection
    Dim child As NotesDocument
    Dim nextChild NotesDocument
    Dim workspace As New NotesUIWorkspace
    Dim tempUIdoc As NotesUIDocument
   
    Set childrens = doc.Responses
    Set child = childrens.GetFirstDocument
   
    While Not child Is Nothing
         Set nextChild = childrens.GetNextDocument(child)
         RecursiveDelete child
         Set child = nextChild
    Wend

    Set tempUIdoc = workspace.EditDocument(False,doc)
    Call tempUIdoc.DeleteDocument
End Sub

Users may notice windows quickly popping open then closing, because Set tempUIdoc = workspace.EditDocument(False,doc) will open the document in the UI and then Call tempUIdoc.DeleteDocument will close the document in the UI and mark it for deletion. I haven't tested this myself but you are more than welcome to give it a try.

Regards,

Scott
0
 

Author Comment

by:marcule
ID: 8282315
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
0
 
LVL 7

Expert Comment

by:scottrma
ID: 8289290
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
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question