How to instantiate Child Object


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I have the following code in my Parent BusinessObject Vlaidation  to ensure that at least one Child is entered.... works fine from my main Parent/Child data entry form

ChildBO myChildBO = (ChildBO)this.ChildBusinessObjects[0];

if (myChildBO.Count <= 0)  { this.AddBrokenRule(this.ITR_CUSREF, "There must be at least one Detail Line"); }

 

Now , on a different form, where I am updating just one field from the Parent Business object, the MyParent.Save() gives an index error, probably because the Child BO is not instantiated. On this partcular form , the Child BI is not used at all.

How do I 'Instantiate' and populate the child Business Object in Code , so that the error does not happen

(I have tried the folloiwng code, but not quite sure what it does...got from another thread)

 

BusinessParentRelationship myRel = new BusinessParentRelationship();
myRel.ForeignKeyField = new string[] { "IDE_ITRPK" };
myRel.ParentPrimaryKeyField = new string[] {"ITR_PK"};
myRel.ParentBusinessObjectType = "ITR";
ChildBO1.ParentRelationship = myRel;
ChildBO1.IdeFillByItrpk(itrBO1.ITR_PK);

 

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerard,

Ger Cannoll (2/20/2012)
How do I 'Instantiate' and populate the child Business Object in Code , so that the error does not happen 

Instead of trying to create a child bo that do not exist, modify your code to test if the ChildBusinessObjects.Count > 0

Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy. Thanks for replying.

That has done the trick....many thanks

Regards,

Gerard


Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
You are welcome Gerard.

Edhy Rijo

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