Q
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.

This was last published in May 2003

Dig Deeper on LotusScript

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchExchange

SearchContentManagement

Close