Good way to set a default field value to a lookup ID?


Author
Message
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
Hi,



Orders

Id

OrderDate

ItemId

OrderStatusTypeId



OrderStatusTypes

Id

Name



Can someone explain a decent way to handle setting a default value for a field that contains the ID of a value in a lookup table?



One way I was considering was in the SetDefaultValues() event handler, creating a temporary LookupBO and using that to get the value based on the name of the value I want as the default.



Or would it be better to do an "this.ExecuteScalar(...)" to get the value I need?



Thank You

Govinda
Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I totally agree with Edhy. I'll add that if you decide to not set a default, I'd return/set an alternate value on NULL (likely zero, as this will work well with the required values check). Then when you get to the UI, you'll likely use a combo and the TopMostValue is your friend. You set it up with a space (or some text indicating they need to choose value) and zero (the alternate value on null) and when the user opens the form, they'll see that the value isn't set.
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
I do know what the default values name should be, but I want to get the value OrderStatusType.Id from the database rather than hardcoding it.



So I was going to do something like this...



private void OrderBO_SetDefaultValues()

{

this.OrderStatusTypeId =

(int)this.ExecuteScalar("SELECT Id FROM OrderStatusTypes WHERE Name = 'OpenOrder'");

}


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