Extend the sample procedure with a dynamic browse
- Last Updated: May 3, 2024
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
If you start with h-CustOrderWin7.w, you can add a dynamic browse to it to illustrate some of the capabilities of this object.
To show all the OrderLines for the current Order in a browse:
- In the Definitions section, add these
definitions:
/* These variables are used just by the dynamic browse variation of this trigger. */ DEFINE VARIABLE hBrowse AS HANDLE NO-UNDO. DEFINE VARIABLE hCalcCol AS HANDLE NO-UNDO. DEFINE QUERY qOrderLine FOR OrderLine SCROLLING.The
hBrowsevariable holds the handle of the dynamic browse you create, andhCalcColholds the handle of a dynamic calculated column for it. The query definition is attached to the browse when you create it. These definitions need to be here at the top level of the procedure so that their values persist beyond the end of the trigger where they are assigned. - Add this statement to the end of the
initSelectioninternal procedure, which sets the list of OrderLine fields in the selection list:OlineFields:ADD-LAST("Price B4 Disc").The new entry represents a calculated column that holds the OrderLine price before the discount is applied.
- In the
LEAVEtrigger for the selection list called OlineFields, comment out all of the code.This code created dynamic fields to display an OrderLine. Now you display a browse in the same place.
- Add these definitions:
/* This block of code is the second version of the trigger, which creates a dynamic browse to show the selected fields. */ DO: DEFINE VARIABLE cFields AS CHARACTER NO-UNDO. DEFINE VARIABLE iField AS INTEGER NO-UNDO. DEFINE VARIABLE cField AS CHARACTER NO-UNDO. - Because you can create a browse over and over again with different lists of columns,
you should first check to see if there is already a dynamic browse and delete
it:
IF VALID-HANDLE(hBrowse) THEN DELETE OBJECT hBrowse. - Add new code to create a dynamic browse. This complex statement defines the browse
and its attributes:
CREATE BROWSE hBrowse ASSIGN FRAME = FRAME CustQuery:HANDLE WIDTH = 50 DOWN = 6 ROW = 9.1 COL = 82 ROW-MARKERS = NO SENSITIVE = TRUE SEPARATORS = TRUE READ-ONLY = FALSE NO-VALIDATE = YES VISIBLE = TRUE QUERY = QUERY qOrderLine:HANDLE. - If necessary, adjust the size and position of the browse according to the layout of your own window and Order browse.
- Add code that walks through the selected fields from the
OlineFields selection list the same as the dynamic
fill-in code does:
cFields = OLineFields:SCREEN-VALUE. DO iField = 1 TO NUM-ENTRIES(cFields): cField = ENTRY(iField, cFields). - If the selected field is the calculated field, you must add a calculated column to
the browse to display it:
IF cField = "Price B4 Disc" THEN hCalcCol = hBrowse:ADD-CALC-COLUMN ("Decimal", /* Data type */ ">,>>>,>>9.99", /* Format */ "0", /* Initial value */ "Price B4 Disc"). /* column label */ - Otherwise, add a column like the selected field in the
OrderLine table:
ELSE hBrowse:ADD-LIKE-COLUMN("OrderLine." + cField). END. /* END DO iField… */ - Add this
ROW-DISPLAYtrigger, which executes each time a row is displayed in the browse:ON ROW-DISPLAY OF hBrowse PERSISTENT RUN calcPriceB4Disc.Because the code in the trigger block for
LEAVEof OlineFields goes out of scope as soon as the trigger block ends, you must put the code for this nested trigger definition in a separate procedure, and use the special syntaxPERSISTENT RUN calcPriceB4Discto make the AVM keep track of what to run when theROW-DISPLAYevent fires. - Add this code to open the OrderLine query:
OPEN QUERY qOrderLine FOR EACH OrderLine WHERE OrderLine.OrderNum = Order.OrderNum.You attached this query to the browse in the
CREATE BROWSEstatement. - Create the
calcPriceB4Discprocedure and add this code:/*--------------------------------------------------------------------- Procedure: calcPriceB4Disc Purpose: Calculates the value of the calculated column PriceB4Disc. Parameters: <none> ---------------------------------------------------------------------*/ IF VALID-HANDLE(hCalcCol) THEN hCalcCol:SCREEN-VALUE = STRING(OrderLine.Price * OrderLine.Qty). END PROCEDURE.A trigger such as this should always check first that its column handle is valid in case it is fired once before the column is created. In this case, the column is optional, so it must always check first to see if it is there.
- In the
VALUE-CHANGEDtrigger for the OrderBrowse, comment out the existing code that blanks out the dynamic fill-ins and replace it with a statement that re-opens the OrderLine query:DO: /* This is the second version of this trigger, for the dynamic browse example. */ OPEN QUERY qOrderLine FOR EACH OrderLine WHERE OrderLine.OrderNum = Order.OrderNum. END.This code refreshes the OrderLine browse each time an Order is selected.
- Run h-CustOrderWin7.w. You can select some
OrderLine fields along with the calculated field and see
the results of your work: