How to add a Field collection to a BO from related BOs?


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
I have a BO which I would like to have access to 2 more related BOs.  The idea is to have a property in the Parent BO to the ChildBO and in this ChildBO to another Child like this:

CustomersBO.OrdersBO.OrderItemsBO.ItemPrice

How can I do that for SF Business Object?

Edhy Rijo

Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
When you call new row, I think is just adds a new row to the data table, with the values being set to whatever is the default for their type. For strings, that is Nothing (null), hence the error.



Don't forget the other part of the code, which is to set values of that new row:

_insuranceCompany.InsuranceCompanyName = String.Empty

...etc.




Do this right after you call NewRow()
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Greg,

So far, the error has nothing to do with setting values to the created new row.  When using BO.NewRow() SF will populate it with the default values which are good enough in my case.

In order to make it work I added a "New" command to initialize the Private BO variable like this:

Private _insuranceCompany As New InsuranceCompanyBO

Then I made some changes to the property code to make sure the BO is filled all the time, like this:

Public ReadOnly Property [InsuranceCompany]() As InsuranceCompanyBO

     Get

          '-- If the private BO has not been created, then create it here.

          If _insuranceCompany Is Nothing Then

               Dim _insuranceCompany As New InsuranceCompanyBO

          End If

          If Not String.IsNullOrEmpty(Me.FK_InsuranceCompany) Then

               _insuranceCompany.FillByPrimaryKey(Me.FK_InsuranceCompany)

          End If

          '-- Check if the BO is empty...

          '-- Initiailize a new row, default values could be added here if needed.

          If _insuranceCompany.Count = 0 Then

               _insuranceCompany.NewRow()

               '-- AcceptChanges on the table, so it isn't dirty (but doesn't save anything to the database)

               _insuranceCompany.CurrentDataTable.AcceptChanges()

          End If

          Return _insuranceCompany

     End Get

End Property

So far the code above is working fine. Smile

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Edhy Rijo - 17 Years Ago
Greg McGuffey - 17 Years Ago
Paul Chase - 17 Years Ago
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Edhy Rijo - 17 Years Ago
                     I am not using a parent-child setup. My custom property in...
Bill Cunnien - 17 Years Ago
Paul Chase - 17 Years Ago
                         Thanks a log guys, I will start playing with the info provided right...
Edhy Rijo - 17 Years Ago
                             Well, here the working version of my code :D [quote][codesnippet]...
Edhy Rijo - 17 Years Ago
                                 This stuff sure is fun!! :w00t: Glad it is working for you...I'll...
Bill Cunnien - 17 Years Ago
                                 [quote]I am sure, there should be something I could add to the...
Edhy Rijo - 17 Years Ago
                                     A couple of thoughts...

First, I don't think you need to...
Greg McGuffey - 17 Years Ago
                                         Sigh...It fubarred my code:crazy:. I didn't use html codes...In any...
Greg McGuffey - 17 Years Ago
                                             Hi Greg, Bill, [quote]Third, on you question about what to do if the...
Edhy Rijo - 17 Years Ago
                                                 Yep, I think the adding the blank row would be very easy. First you...
Greg McGuffey - 17 Years Ago
                                                 Humm, This is getting better :D when changing the code as follow:...
Edhy Rijo - 17 Years Ago
                                                     When you call new row, I think is just adds a new row to the data...
Greg McGuffey - 17 Years Ago
                                                         Greg, So far, the error has nothing to do with setting values to the...
Edhy Rijo - 17 Years Ago
Edhy Rijo - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search