Home > Ask the Domino Experts > Questions & Answers > How can LotusScript be used to update the children of a document when the parent doc is saved?
Ask The Domino Expert: Questions & Answers
EMAIL THIS

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

Andre Guirard EXPERT RESPONSE FROM: Andre Guirard

Pose a Question
Other Domino Categories
Meet all Domino Experts
Become an Expert for this site
>
QUESTION POSED ON: 28 May 2003
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.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Lotus Notes Domino on Blackberry and mobile devices
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2010, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts