Parent & Response documents- LotusScript help

Client Based only:

I have a parent document that when you click a button creates 8 response documents. How would I mark all of the response documents to be deleted IF I DELETE the Parent.

In other words: If the user decides to delete the parent or main document I would then want all subsequent response documents(child) to be marked as deleted.

Any help would be appreciated.

Thanks,

ccl

and Happy New Year

Subject: Parent & Response documents- LotusScript help

If those 8 response are all direct descendents of the parent, then you can get a handle to all 8 by using the Response property of NotesDocument and then remove them all in one shot with the RemoveAll method in NotesDocumentCollection.

If responses to responses are involved then that won’t work. You’ll have to build some recursive routine to check for responses to responses. Or if the parent has some unique identifier that is passed onto the responses, you could do a simple search to get all responses and delete them that way.

Hope that helps.

Subject: Parent & Response documents- LotusScript help

you can add code to Querydocumentdelete event (in database script). your code should check if the document has responces and if it is so → remove all responces.

Dmytro Pastovenskyi

Subject: RE: Parent & Response documents- LotusScript help

Well, yesa, but this still doesn’t capture e.g. deletions from the back-end.

Subject: Parent & Response documents deletion- Singleton and Strategy Pattern

Yes, It’s a fairly tricky issue to solve.

You can do this with good OOP.

You have to create :

  • a Database class to improve NotesDatabase

  • a Document class to improve NotesDocument

  • a ParentStrategy class

assuming you have two kind of document; “Question” and “Answer”.

Create a DocumentAnswer class extending Document

Create a DocumentQuestion class extending Document and using ParentStrategy

Create a DocumentFactory methode in charge of Document creation depending of NotesDocument passed in param

(

Function DocumentFactory(Source as NotesDocument) as variant

Select case Source.Form(0)

Case “Answer”

Set DocumentFactory = New DocumentAnswer(Source)

Case “Question”

Set DocumentFactory = New DocumentQuestion(Source)

Case else

Set DocumentFactory = New Document(Source)

End Select

End Function

)

In Document class add QueryDelete, QueryUnDelete and Remove methode

(

Sub QueryDelete(Continue as variant)

If not Me.ParentStrategy is nothing then

    Call Me.ParentStrategy.QueryDelete(Continue)

end if

End sub

Sub QueryUnDelete(Continue as variant)

If not Me.ParentStrategy is nothing then

    Call Me.ParentStrategy.QueryUnDelete(Continue)

end if

End sub

Function Remove(Force as Integer) as Integer

If not Me.ParentStrategy is nothing then

    Remove = Me.ParentStrategy.Remove(Force)

end if

End Function

)

Me.ParentStrategy.QueryDelete and QueryUnDelete aim to manage child deletion

In the Database Class add Querydocumentdelete, QueryDocumentUndelete and PostDocumentDelete methodes to trap deletions stub

Add also RemoveDocuments(NotesDocumentCollection) and RemoveDocument(NotesDocument) to manage removing without deletion flag

e.g.

Sub QueryDocumentDelete(Source as NotesDocumentCollection, Continue)

Dim CurrentDoc as NotesDocument

Dim NextDoc as NotesDocument

Dim Doc as Variant

Set CurrentDoc = Source.GetFirstDocument

Do until CurrentDoc is nothing

Set NextDoc = Source.GetNextDocument(CurrentDoc)

Set Doc = DocumentFactory(Source)

Call Doc.QueryDelete(Continue)

Set CurrentDoc = NextDoc

Loop

End Sub

Add a CurrentDatabase Methode to prevent memory leak

Static Property Get CurrentDatabase (boForce as Variant) as Variant

Dim Session as New NotesSession 'This can be a global variable

Static SINGLETON as Variant

If Isempty(SINGLETON) or boForce then

Set SINGLETION = New Database(Session.CurrentDatabase)

end if

Set CurrentDatabase = SINGLETON

End Sub

Then in Database script :

Declare a UIDatabase as variant

In postopen

Set UIDatabase = CurrentUIDatabase(False)

In QueryDocumentDelete

If UIDatabase Is Nothing Then

Set UIDatabase = CurrentDatabase(False)

End If

UIDatabase.QueryDocumentDelete Source.Documents, Continue

As in QueryDocumentUndelete, PostDelete (to adapte)

Any where in your code use CurrentDatabase.RemoveDocument or .RemoveDocuments

If You only Work with Document use DocumentFactory to create Document object then use Remove methode.

Subject: RE: Parent & Response documents deletion- Singleton and Strategy Pattern

And - others have put up their plugs before - you can support my proposal on IdeaJam:

http://ideajam.net/IdeaJam/P/ij.nsf/0/88290C3C0077496F862573C4006263AD?OpenDocument