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
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
Hi Govinda,

I don't fully understand your question, but if you are creating an Order and want to update the OrderStatusTypeID you can use a combobox to allow the user to select the Status, or if you know that the status for new orders will be 1 or 2 simply use the Orders business object SetDefaultValues to assign the default value.

Private Sub OrdersBO_SetDefaultValues()

     Me.OrderStatusTypeId = 1

End Sub



Edhy Rijo

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
Thanks for the reply Edhy.



I guess I'm trying to find a way not to hard-code IDs. But I think that's what I should do anyway rather than worry about IDs changing down the line (ie Deployment).

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
Govinda Berrio (08/20/2008)
Thanks for the reply Edhy.

I guess I'm trying to find a way not to hard-code IDs. But I think that's what I should do anyway rather than worry about IDs changing down the line (ie Deployment).

If you don't know the description of the StatusID, then don't assign any as a default, simply mark that field as a Required field in the BO, and use the combobox to allow user to select whatever ID they want to use.

If this feature is a most, later on, you can have a Setup Option form which will allow the end user to select Default Values for some fields and then you can use those values in the Setup Option BO as default for your regular BOs.

Edhy Rijo

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