Some time ago I really liked to work
with response documents in Lotus Notes. I appreciated the way to show the
direct relation between documents. Recently I didn't used them as much
because in some circumstances they are not flexible enough. Now that I
found this strange bug my trust in the response hierarchy is gone.
In an application the main document
should be copied including all the response documents. Using NotesDocument.CopyToDatabase
and NotesDocument.MakeResponse it was no big deal. But suddenly the users
complained that while deleting the main document the wrong response documents
was deleted too.
There was some code in the Postdocumentdelete
event to delete all the response by using the property NotesDocument.Responses.
Actually I took my some time to figure
out where the problem was. I created a small test database for that purpose.
In the database I created a main document and two responses.
A little LotusScript agent helped me
to create copies the same way as in the original database. First everything
looked fine. The $Ref field in the copied response documents had a reference
to the copied main document.
Because it is hard to show the deletion
of documents in a screen shot I decided to color the documents in the view
instead. To do so I grabbed the main document and with the property NotesDocument.Responses
all his responses and changed the color value.
I was quite surprised to find that repeatable
the first response of the copied documents had also changed its color.
This effect was there in Notes 6.5.6 and Notes 7.0.3.
With some trial and error I could isolate
the error.
Set
docCopy = db.CreateDocument
Call docOriginal.CopyAllItems(docCopy)
Call docCopy.ReplaceItemValue("Subject", docOriginal.GetItemValue("Subject")(0) & "
(Copy)")
If docOriginal.Responses.Count <> 0 Then
Call
CopyResponses(docOriginal, docCopy)
End If
Call docCopy.Save(True,
True, True)
While creating the copies the copy of
the main document has been saved after the response documents has been
copied and assigned to the copied main document. After I changed the order
to first copy and then save everything worked as aspected.
If you want to try it yourself here
is the sample database.
Update:
Here is the code that avoids this mistake.
Set
docCopy = db.CreateDocument
Call docOriginal.CopyAllItems(docCopy)
Call docCopy.ReplaceItemValue("Subject", docOriginal.GetItemValue("Subject")(0) & "
(Copy)")
Call docCopy.Save(True, True, True)
If docOriginal.Responses.Count <> 0 Then
Call
CopyResponses(docOriginal, docCopy)
End If