Auto add row to child bo when add row to parent bo


Author
Message
Attila Dobozi
Attila Dobozi
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 14
I have three business objects on a maintenance form, Parent, Child, Grandchild.  The Child and Grandchild are both filled for the Parent.  The Grandchild contains all rows that belong to all Child rows for the current Parent.  The Child.ChildAutoFilterOption = MatchCurrentRow.

The Parent is tied to the MaintenanceToolstrip.  The Child is tied to a second, custom, toolstrip.
When Parent changes the Child and Grandchild are filled appropriately.  Navigation and editing work.

When adding a Child I want to also add a Grandchild.  In the custom toolstrip cmdAdd.Click() function I call Child.AddNew().  The Child.AfterAddNew() event calls GrandChild.Add().  When I trace into the GrandChild.SetDefaultValues() I see that the field values show the previous GrandChild row data instead of the new row data (the GrandChild pk is not -1).  It looks like I'm overwriting the previous GrandChild row's data with default values. 

There is a GrandChild_Navigated event on the form where I messagebox the Child and GrindChild pks.  The messagebox does not popup after the GrandChild.AddNew() or GrandChild.SetDefaultValues().  The messagebox pops once with Child.pk = -1 and GrandChild.pk = 88 (prev GrandChild.pk value) and immediately pops again with Child.pk=-1 and GrandChild.pk = -1. 

... a day later ...

Never mind.  If I call GrandChild.Add() in the cmdAdd.Click() after calling Child.Add() it works.  It looks like the Child_AfterAddNew() event occurs before the Child filter and GrandChild navigation occurs so GrandChild defaults are assigned to the wrong row.  So the lesson is don't call AddNew() on a child bo from the parent's AfterAddNew event.  I'm evaluating SF so couldn't trace into its source otherwise I would've figured this out sooner.

Reply
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
So far I couldn't find a way in SF to refresh only the current Parent row from the database. 

I am not sure what you are referring to by Refresh.  Are you referring to updating the data back to the server or refreshing the UI?

I looked at the AppendDataTable function, hinted at by another post, but could not make it work and could not find it in the help.

Use the CopyDataFrom method on the BO.  If you only want a single record, then fitler out the records on the source BO or data tables default view, then either do an append or clear and fill on the second parameter using the view option.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search