Setting up a grid / BO with related fields


Author
Message
thegwill
thegwill
StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)
Group: Forum Members
Posts: 16, Visits: 177
In my database I have TableA which has a FK to TableB

In my project I have BizObA which consists of fields from TableA. I would also like it to include a field from TableB as it's related via an FK

If I were writing the SQL it would be something like:

SELECT A.Field, A.AnotherField, B.SomeField
FROM TableA A
INNER JOIN TableB B
ON A.FK = B.PK

...but I'm not sure how this is achieved using the BO Mapper so that BizObA truly represents my business object and not just reflects a table structure

I guess I could have a separate BizObB to point at TableB and stitch them together but this seems like a bad idea

Once I have my BizObB I want to bind it to a grid using the BBS...

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Check out custom fields in help. I do this all the time. They can be setup to be bindable also.
thegwill
thegwill
StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)
Group: Forum Members
Posts: 16, Visits: 177
Thanks Greg but this isn't really what I'm after. I understand the custom field concept but I am looking to retrieve the "custom field" from a related table as per the SQL

If I were to follow the "custom field" approach then surely I would need to hit the database again? This is what I am trying to avoid...

Peter Jones
Peter Jones
Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)Advanced StrataFrame User (522 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Guys,

A fortuitous thread - I think I have the a similar issue and was going to go down the custom field path but, before I start working out how to do that, perhaps you can say if the custom field approach will work in my case.

I have a BO based on a table that has three FKs which are not maintainable in the BO however I want to show the “Name” associated with each FK when I display the row details in a grid. My cunning plan was:

1) Create the BO on the table.
2) Use a stored procedure to populate the BO that has all the columns in the source table plus joins on the three FKs so I can extract the Name value associated with each FK value. This will give me three extra columns: Name1, Name2 and Name3.
3) I was then going to create three custom fields in my BO called (you guessed it) Name1, Name2 and Name3.

I then “hoped” that when I created my Business Binding Source the custom fields would be visible so that I could include them in my grid and these fields would be automatically bound to Name1 etc from the stored proc. Is this the way it works?

Cheers, Peter

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
thegwill, if I understand what you are trying to accomplish, then I am going to add to Greg's comment.  You do not have to actually have the field strong-typed through the BO mapper.  Let assume that you want to create an alias field or produce a custom field via your query, then even without creating a custom property on the BO you can access that field through the Item property on the BO.  The field will exist in the internal data table but it will just not have a strong-typed property.  So you could then create a custom property to access it if the need exists.  Let me know if this is what you are trying to accomplish.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
1)Create the BO on the table.

2)Use a stored procedure to populate the BO that has all the columns in the source table plus joins on the three FKs so I can extract the Name value associated with each FK value. This will give me three extra columns: Name1, Name2 and Name3.

3)I was then going to create three custom fields in my BO called (you guessed it) Name1, Name2 and Name3.





Just one more step:



4. Override the GetCustomBindablePropertyDescriptors method to include each of the custom properties that you want to be bindable. There is info about this in help (I think). If you have trouble, I'll post an example.





Note that if your custom properties are readonly, then the BO will never enable them for editing (assuming normal SF binding).



You might also want to track when you call the fill method that fills the BO with the FK names, so you can gracefully handle (or informatively throw an exception) if you access on of the properties when those extra columns are in the data table.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
You do not have to actually have the field strong-typed through the BO mapper. Let assume that you want to create an alias field or produce a custom field via your query, then even without creating a custom property on the BO you can access that field through the Item property on the BO. The field will exist in the internal data table but it will just not have a strong-typed property. So you could then create a custom property to access it if the need exists.




There are about a million bloody ways to access data with SF. I'm constantly amazed. I hadn't thought of this way at all....Blink
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Ah...yeah, thanks Greg.  That is correct...and a very important step BigGrin  I was trying to answer the forum questions last night with a pounding headache...stupid I know Blush .... but today...headache gone and back to work BigGrin
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad the headache is gone...that is never fun.
thegwill
thegwill
StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)StrataFrame Beginner (16 reputation)
Group: Forum Members
Posts: 16, Visits: 177
Thanks for the tip(s) guys. The day job is taking over at the moment so I'll give it a try soon...

BTW, it would be really helpful to have a "recipe" book of such topics for SF noobs like myself (you know the kind of thing, like the o'reilly books).

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