Custom Fields on Business Object


Author
Message
Tim Dol
Tim Dol
StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
Is it possilbe to create a custom field in a business object to store temporary data for each row without creating a actual field in the database.

I tried creating a custom field in the business object and a Private variable to store and retrieve the value but it appears to only keep the last value.

I'm open to suggestions if this isn't the correct approach.  Basically I want to end up with a place to store / retrieve information in the business object for each row without having to create an extra field in the table.

Thanks

Tim

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

Please take a look at the following topic in the SF help file "Custom Field Properties, Adding Custom Field Properties" it will show you how to do what you are looking for.

Good luck!

Edhy Rijo

Tim Dol
Tim Dol
StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
I've used custom field properties many times as described in the help, but these are read-only. I need the ability update the custom field as well, just like a normal field. Perhaps I'm missing something here but I can't seem to achieve the desired results with the read-only property.

Thanks

Tim

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Tim,



Instead using a private variable, use a private dictionary, with the key being the PK and the value being whatever you want to store...so....



' Holds data for custom temp property.

' In this case, the PK is an integer and MyProp will hold a string.

Private _myProp As Dictionary(Of Integer, String)



' Of course, this would need the attributes to make a bindable property

Public Property MyProp As String

Get

' If dictionary hasn't been set yet, return a ZLS

If _myProp Is Nothing Then Return String.Empty



' Where PKField is the strong typed property that accesses the PK of the BO

Return _myProp(Me.PKField)

End Get

Set(value As String)

' check that the dictionary is initialized

If _myProp Is Nothing Then

_myProp = New Dictionary(Of Integer, String)

End If

_myProp.Add(Me.PKField,value)

End Set

End Property


Tim Dol
Tim Dol
StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
Greg, this is perfect. Thanks a lot! Smile
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Any time BigGrin
Larry Caylor
Larry Caylor
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K
Another method that I use to store the temporary custom fields in the BOs data table. I usually add the custom colums in the select statement that fills the BO. Once the colums have been added I use the custom field properties to maintian them.

<Browsable(False), _
BusinessFieldDisplayInEditor(), _|
Description(
"Custom field"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Property cust_Field() As String
  
Get
       
Return Me.CurrentRow.Item("CustomField").ToString
  
End Get
  
Set(ByVal value As String)
      
Me.CurrentRow.Item("CustomField") = value
  
End Set
End Property

Since the BO uses the AllFieldsNames property when saving or updating the object, the added fields are simply ignored.

-Larry

 


Tim Dol
Tim Dol
StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)StrataFrame User (446 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
I'm trying to use these properties on grids so I added the custom bindable property descriptions but when I try to update I get an error indicating that the field isn't part of the business object.

Are these properties supposed to be bindable?

Thanks

TIm

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'm wondering if the problem is that you are using a grid. I'm thinking out loud here...normal SF data binding is controlled by the BO but binding to a grid is through a BusinessBindingSource to the DataTable, so that might be the problem.



If the extra data is temporary and you don't need to persist it, then the dictionary method would likely work better. If you do need to persist it, then it looks like it could get complicated. Sorry this isn't a more definitive answer Unsure I hope this helps you keep moving on the problem though Smile



Paul Chase
Paul Chase
Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)Advanced StrataFrame User (592 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Gregg is probably on the right track.

I had quite a bit of trouble using the BBS and ended up making my own class for that. 

Basically what happens with a BBS is for every row in the business object that you are binding to, a new instance of the business object is created and represent that row and its datatable is shared with the first main bo.

The problem is that if you have any properties , events etc set on the main bo the lose they're values in the newly created instance. hope that makes sense

However I would think because the datatable is shared you should be able to make it work somehow.

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