Populate Code Tables from constants

Share this topic:



Link to this posting

Postby Ursego » 24 May 2013, 12:07

Creating a control with a Code Table (like DropDownListBox or RadioButton), populate its Code Table programmatically if constants are defined in the application for the added values (instead of hard-coding in the DataWindow painter). That is done using the SetValue() method of DataWindow.

For example, you have to create a radio button for the field "payment_method" in your DW while constants n_payment_method.CREDIT_CARD (with value "C") and n_payment_method.PAYPAL (with value "P") exist in your system (see here):

Code: Select all
dw_payment.SetValue("payment_method", 1, "Credit Card~t" + n_payment_method.CREDIT_CARD)
dw_payment.SetValue("payment_method", 2, "PayPal~t" + n_payment_method.PAYPAL)

The easiest way is to simply hard-code the values "C" and "P" in the DataWindow painter. But what if those system codes will be changed in the future? In fact, that's why we utilize constants at all: it's enough to change one value (of the constant itself) and that automatically changes it in the whole system so the existing logic keeps working. I don't believe you will argue about using constants in PowerScript; but if you use constants only in PowerScript (forgetting about Code Tables and, by the way, SQL SELECTs of DWs, to which the constsant must be sent as parameters), it won't be "in the whole system"... :cry:

Prefer the correct programming, not the quickest!
User avatar
Ursego
Site Admin
 
Posts: 111
Joined: 19 Feb 2013, 20:33

Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 2 guests


Populate Code Tables from constants

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





free counters

eXTReMe Tracker