Consultor Eletrônico



Kbase 18375: How to Get a SmartObject Foreign Key Value for Field Assign
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Verified

GOAL:

ADM. How to get a key value for a foreign field in a SmartObject that is a record target from another SmartObject.  This key value can then be used to assign a key field in a new record.

FACT(s) (Environment):

Progress 8.1x

FIX:

This example contains a SmartQuery for customers.  

The SmartQuery supplies a Cust-Num foreign key to a SmartBrowser for orders which will display all orders for the current customer in the SmartQuery.

The SmartBrowser is linked to a SmartViewer where order records can be created, and the customer number is needed to assign the Cust-Num field for the newly created order.

1) Create a SmartQuery for customers that supplies Customer.Cust-Num foreign key.

2) Create a SmartBrowser for orders that accepts Order.Cust-Num foreign key.

3) Create a SmartViewer for orders that will be used to add and update orders.

4) Create a SmartWindow with the above created objects and Navigation and Update SmartPanels with the following links:

Customer SMQ           Record Link          Order SMB
Order SMB              Record Link          Order SMV
Update SMP             TableIO Link         Order SMV
Navigation SMP         Navigation Link      Customer SMQ

5) Create a local-assign-statement override procedure in the order SmartViewer with the following code:

DEFINE VARIABLE c-rechdl AS CHARACTER NO-UNDO.
DEFINE VARIABLE rhdl AS HANDLE NO-UNDO.

/* Code placed here will execute PRIOR to standard behavior. */

/* Dispatch standard ADM method.                             */

RUN dispatch IN THIS-PROCEDURE ('assign-statement').

/* Code placed here will execute AFTER standard behavior.    */

RUN get-link-handle IN adm-broker-hdl (THIS-PROCEDURE, 'RECORD-SOURCE', OUTPUT c-rechdl).

ASSIGN rhdl = WIDGET-HANDLE(c-rechdl).

IF VALID-HANDLE(rhdl) THEN
DO:
    RUN get-attribute IN rhdl ('KEY-VALUE').
   ASSIGN Order.Cust-Num = INTEGER(RETURN-VALUE).
 END.  /* if valid handle */

END PROCEDURE.

This code will get the handle of the SmartViewer's Record Source which is the order SmartBrowser.  This SmartBrowser uses the Cust-Num foreign key in order to be linked to the customer SmartQuery.  This foreign key value is stored in a KEY-VALUE attribute which this code retrieves to assign the new order's customer number.