en · de

LotusScript: CopyToDatabase screws up NotesDocument.Responses

by Bernd,
assono GmbH, Standort Hamburg,


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 picture named M2

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.
A picture named M3

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.
A picture named M4

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.
A picture named M5

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 zip.gif 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

Technical article Development

You have questions about this article? Contact us: blog@assono.de

Sie wollen eine individuelle Beratung oder einen Workshop? Read more

More interesting entries

Any questions? Contact us.

If you want to know more about our offers, you can contact us at any time. There are several ways to contact us for a non-binding first consultation.

assono GmbH

Location Kiel (headquarters)
assono GmbH
Lise-Meitner-Straße 1–7
24223 Schwentinental

Location Hamburg
assono GmbH
Bornkampsweg 58
22761 Hamburg

Phone numbers:
Human resources department: +49 4307 900 407
Marketing department: +49 4307 900 411

E-Mail adresses:
contact@assono.de
bewerbung@assono.de