Kbase P3572: How to drive a SmartSelect datasource with Foreign Fields from a parent SDO.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  25/01/2005 |
|
Status: Unverified
GOAL:
How to drive a SmartSelect datasource with Foreign Fields from a parent SDO.
FACT(s) (Environment):
Progress 9.x
Windows 32 Intel
FIX:
Add a Foreign Field Link within the SmartDataViewer InitializeObject override procedure from the parent SDO to the contained SmartSelect SDO.
Get handle of SmartSelect SDO and then use "addLink" to add a "Data" link between the Parent SDO and the SmartSelect SDO. Then use "SetForeignFields" to specify the fields to link the SDO's.
As and example, if you create a smartSelect on a database table that lists discount percentages against customers. A customer can have several different percentage rates that can be displayed in the smartSelect.
The smartselect is used in an orderline SmartDataViewer, which is driven from an orderline SmartDataObject. The orderline SDO has a parent order SDO that is linked by the ordernum foreign field. The order SDO is also a data source for an order SmartDataBrowse, such that as the order browse is navigated the first orderline for that particular order is displayed in the orderline SmartDataViewer.
Place the following code in an initializaObject override procedure of the SmartDataViewer. This creates a link between the order SDO and the smartSelect SDO via the customer number foreign field. In addition there is a subscription to the VALUE-CHANGED event in the browser. The viewer responds to this by publishing 'DataAvailable' from the order SDO. This ensures that the correct value is displayed in the smartSelect as records are navigated in the order browse.
/* Code placed here will execute PRIOR to standard behavior. */
RUN SUPER.
/* Code placed here will execute AFTER standard behavior. */
DEFINE VARIABLE wx-fieldhandles AS CHAR NO-UNDO.
DEFINE VARIABLE wx-fields AS CHAR NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE h_field AS HANDLE NO-UNDO.
DEFINE VARIABLE c_browse AS CHARACTER NO-UNDO.
DEFINE VARIABLE h_SDO AS HANDLE NO-UNDO.
DEFINE VARIABLE h_orderlineSDO AS HANDLE NO-UNDO.
DEFINE VARIABLE h_orderSDO AS HANDLE NO-UNDO.
DEFINE VARIABLE h_browse AS HANDLE.
wx-fieldhandles = DYNAMIC-FUNCTION('getFieldHandles':U IN TARGET-PROCEDURE).
wx-fields = DYNAMIC-FUNCTION('getDisplayedFields':U IN TARGET-PROCEDURE).
h_orderlineSDO = DYNAMIC-FUNCTION('getDataSource':U IN TARGET-PROCEDURE).
h_orderSDO = DYNAMIC-FUNCTION('getDataSource':U IN h_orderlineSDO).
c_browse = DYNAMIC-FUNCTION('getDataTarget':U IN h_orderSDO).
/* Get handle of the order browse */
DO i = 1 TO NUM-ENTRIES(c_browse):
h_field = WIDGET-HANDLE(entry(i,c_browse)).
IF dynamic-function('getObjectType':U IN h_field) =
"SmartDataBrowser" THEN
DO:
h_browse = h_field.
LEAVE.
END.
END.
SUBSCRIBE "BrowseValueChanged" IN h_browse.
/* Create a Data link and set Foreign Fields between order and
SmartSelect SDO */
DO i = 1 TO NUM-ENTRIES(wx-fieldhandles):
h_field = WIDGET-HANDLE(entry(i,wx-fieldhandles)).
IF i = 8 THEN
DO:
h_SDO = DYNAMIC-FUNCTION('getDataSource':U IN h_field).
RUN addLink IN h_SDO
( INPUT h_orderSDO /* HANDLE */,
INPUT "Data" /* CHARACTER */,
INPUT h_SDO /* HANDLE */).
DYNAMIC-FUNCTION('setForeignFields':U IN h_SDO,
INPUT "Itemdiscount.custnum,custnum").
END.
END.