Problem solve Get help with specific problems with your technologies, process and projects.

How can LotusScript be used to update the children of a document when the parent doc is saved?

I am trying to make LotusScript update the children of a parent document when the parent document is saved. One problem: The children documents are not truly setup as responses, they're just a separate form. Can you push me in the right direction? Thanks in advance for your help.

I'm assuming that there is some unique field that the "parent" and the "children" documents have in common; otherwise your situation is hopeless. Let's suppose that a parent's AccountID field is the same as the ParentAccountID field in the children.

You need a view of the children documents sorted by ParentAccountID. When you need to update the children documents, you could then use code such as the following in the Postsave event of the parent document:

Set parentDoc = Source.Document
Set view = db.GetView("ChildrenByAccountID")
Set col = view.GetAllDocumentsByKey(parentDoc.AccountID(0))
If col.Count > 0 then
' there are some children documents. Update the AccountName field in these documents.
col.StampAll "AccountName", doc.AccountName
End If

StampAll is nice if there is just one field you need to update. If there is more than one you should use GetFirstDocument, GetNextDocument to loop through the children documents and make the appropriate updates.

Note, however, that there are potential problems with doing this kind of update, no matter how you write the code. In a replicated environment like Notes, there's no way to be certain that the children documents you have in the current replica are all the children documents there are -- there may be some created in another replica that haven't arrived here yet. Plus, since other users -- or the current user! -- may be editing some of the children documents at the time your script runs, there's a chance of save conflicts.

You might consider not storing duplicate copies of fields at all -- instead, use @DbLookup to display the values in "computed for display" fields in the child document. Or if you must have the copies -- for example, because the values have to appear in views -- you might have to add overnight agents to make sure any recently modified documents contain consistent information.

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...