Updating parent field whenever child document is updated

I have a Lotus application based on the Discussion template, where the Main Topic form can have children Response forms associated with it. The children form has a DoclinkParent computed field that has a $Ref back to the parent, in order to display the parent’s Subject title. What I would like to do is the opposite- update the Modified Date field on the parent document whenever a child document has changed. This is so that if any child record is updated for an old parent record, the parent record bubbles up to the top of the default view, which is sorted by modified date. Currently the default view does not update a parent document even if it has new or updated response documents associated with it, so no one knows that it was recently updated.

thanks,

Won

Subject: querysave of the child

You would want to do something in the querysave event of the child document that would do a lookup to the parent document and make a change to that document. Then, every time the child document is saved, it will make a change to tha parent, which should give you the updated modified date you’re looking for.

Subject: Updating parent field whenever child document is updated.

I finally got around to implementing this function. I realized you have to code this in the Postsave method when the child document is saved b/c there are no values (or updated values) for the child until it is saved. Keep in mind this is only for the Notes client save- not sure how this can be done for web saves. Here is my code in Postsave:

Sub Postsave(Source As Notesuidocument)

Dim s As New NotesSession

Dim db As NotesDatabase

Dim parent As NotesDocument

Dim parentLastModified As Variant

Dim parentEditHistory As Variant

Dim childEditHistory As Variant

Dim newParentEditHistory As Variant

Dim childLastModified As Variant

Dim item As NotesItem



Set db = s.CurrentDatabase



'Get the parent document (Main Ticket) from the child document that was just saved.  This routine must be in the Postsave method b/c this document does not become a child until it is saved.

Set parent = db.GetDocumentByUNID( Source.Document.ParentDocumentUNID )



parentLastModified = parent.LastModified

childLastModified = Source.Document.LastModified



'Replace the LastModified field in the main ticket with the last modified time from the Additional Source

Call parent.ReplaceItemValue(parentLastModified, childLastModified)



parentEditHistory = parent.GetItemValue("PreviousAuthors")



'Add a new line with a notification of when the Modified Date field was edited- when the Additional Source was last edited.

newParentEditHistory = parentEditHistory(0) + Chr(10) + "An Additional Source to this ticket was created/modified on " & childLastModified	

Call parent.replaceItemValue("PreviousAuthors", newParentEditHistory)



Call parent.Save(True, True)

End Sub