Write a VALUE-CHANGED trigger for the browse
- Last Updated: January 16, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Now you need to write the code to run the h-OrderCalcs.p procedure. When
does this need to happen? Whenever a new row is selected in the list of
Orders for a Customer. This is called
the VALUE-CHANGED event for the browse.
To write the trigger for the browse:
- Click on the browse to select it, then click the Edit Code
icon in the toolbar. The Section Editor appears.
The default code block to define for a browse is the
VALUE-CHANGEDtrigger, so this comes up automatically. - Fill in the empty
DO-ENDblock with this code:DO: RUN h-OrderCalcs.p (INPUT Order.OrderNum, OUTPUT dTotalPrice, OUTPUT dTotalExt). dAvgDisc = (dTotalPrice - dTotalExt) / dTotalPrice. DISPLAY dTotalPrice dTotalExt dAvgDisc WITH FRAME CustQuery. END.
This code runs the procedure, passes in the current Order number, and
gets back the two values that map to the fill-in fields you defined. These are really
just variables, but the AppBuilder generates definitions with a special phrase added to
turn the variable into a value that can be displayed in the window as a proper GUI
control. This is the VIEW-AS phrase and here is one of the three
variable definitions the AppBuilder generates:
|
The SIZE width BY height phrase
defines the display size of the fill-in field. A DEFINE VARIABLE
statement can specify all the different kinds of ways a single field value can be
displayed, including toggle boxes for logical values, selection lists, and editor
controls, using the VIEW-AS phrase.
RUN statement, the code does a calculation of its own to
determine the average discount and stores that value in the third fill-in
field:
|
|
As you can see, this DISPLAY statement looks exactly like the
DISPLAY statements you have been using in the little examples
earlier. But because the fields are given the specific display type of
FILL-IN, they show up as GUI controls rather than just in the
report-like format you get by default.
To see the effects of your changes, Run the procedure. When you first run it, the fields come up with zeroes in them. But when you click on another row of the browse, then the calculations appear correctly:
The VALUE-CHANGED event happens only when you actually select a row in
the browse, not when it is first populated with data. To correct this, you need to apply
that event when the window is first initialized and also whenever the user selects a
different Customer.