Update of parent when child is deleted

HiI need to update accumulators on the parent when deleting a child. I’ve tried to call the code below (residing in the script library) from querydocumentdelete. However it seems that “respdoc.isdeleted” is not working, i.e. the respdoc is not marked as deleted…

Any help would be appreciated.

Sub updateMainActivity (db As NotesDatabase, doc As NotesDocument)

Dim session As New notessession	

Dim madoc As notesdocument

Dim respdoc As notesdocument

Dim collection As notesdocumentcollection



'Get parent document (MainActivity)

parentUNID = doc.ParentDocumentUNID

Set madoc = db.GetDocumentByUNID(parentUNID)



'Set defaultdata from children

...



Set collection = madoc.Responses

If Not collection Is Nothing Then

	'** Get data from Activity **

	For count = 1 To collection.count

		Set respdoc = collection.GetNthDocument(count)			

		If Not (respdoc.IsDeleted) Then

			If respdoc.Form(0) = "Activity" Then

			... accumulate child values	

			End If				

		End If

	Next			



	'************** Update MainActivity *********************

	....update accumulators on parent doc

	Call madoc.Save(True,False)

End If

End Sub

Subject: RE: Update of parent when child is deleted

The point of the querydocumentdelete is to give you a chance to carry out actions before the document is deleted. So naturally, IsDeleted is not true – yet. Plus, I don’t think it’s definite at this point that the user will be allowed to delete the documents (because of Authors felds, etc).

Postdocumentdelete would be a better place to check. But, because you can’t pull any information from documents that have really been deleted, this is also called before the documents are really gone – but far enough along that you know that they will be deleted. You will have to iterate thru the documents that are about to be deleted, and adjust the totals in the parent documents by subtracting these. There is still not a way at this point to calculate the total “from scratch” without paying attention to the list of documents about to be deleted, which the system has given you in NotesUIView.Documents.

This is off the top of my head and might not be correct in all details.