In the previous exercise, you've implemented determinations in the base BO Behavior (see Exercise 8).
In the present exercise, you will define side effects for the travel BO root entity to trigger a reload of the Fiori elements based Travel app.
- 9.1 - Define Side Effects in the base Travel BO Behavior
- 9.2 - Expose Side Effects in the Travel BO Behavior Projection
- 9.3 - Define Side Effects in the _Travel_BO Behavior Projection
- 9.4 - Preview and Test the Enhanced Travel App
- Summary
Reminder: Do not forget to replace the suffix placeholder
###
with your choosen or assigned assigned suffix in the exercise steps below.
Side effects are used to trigger data, permission, or message changes based on data changes in UI scenarios with draft-enabled BOs.
They are useful in UI scenarios based on draft-enabled BOs to notify a Fiori Elements UI that data changes of defined fields require the recalculation of other data values, permissions or messages.
Further reading: Side Effects
Define Side effects to trigger the recalculation of the total price (
TotalPrice
) each time the fields the booking fee (BookingFee
), the currency code (CurrencyCode
), and the flight price (FlightPrice
) of the travel or the booking entities change on the UI.Also define Side effects so that begin date (
BeginDate
) and the end date (EndDate
) of the travel entity are validated each time they are changed.
🔵 Click to expand!
Define side effects for the fields
TotalPrice
,BeginDate
, andEndDate
of the travel entity.
🟣 Click to expand!
-
Open the behavior definition of the travel BO entity
ZRAP110_R_TRAVELTP_###
. -
Define the side effects for the recalculation of the total price.
Field triggers are the elements
BookingFee
andCurrencyCode
, and the field target (or affected field) is the elementTotalPrice
.Insert the code snippet provided below after the determinations as shown on the screenshot.
//side effects side effects { field BookingFee affects field TotalPrice; field CurrencyCode affects field TotalPrice; }
-
Define the side effects to trigger the validation of
BeginDate
andEndDate
.For that the defined
determine action checkDates
defined in Exercise 3.4 will be called each timeBeginDate
andEndDate
are changed. The respective messages should be reloaded whenever available.ℹ A
determine action
allows you to specify trigger points for when validations and determinations should be invoked.Add following code snippet to the
side effects
definition as shown on the screenshot:determine action checkDates executed on field BeginDate, field EndDate affects messages;
Define side effects for the fields
TotalPrice
of the parent travel entity.
🟣 Click to expand!
-
Open the behavior definition of the booking BO entity
ZRAP110_R_TRAVELTP_###
. -
Define the side effects for the recalculation of the total price of the target travel entity each time the flight price or the currency code of the booking entity changes.
Field triggers are the elements
FlightPrice
andCurrencyCode
, and the field target (aka affected field) is the element_Travel-TotalPrice
of the target parent Travel entity.(
_Travel.TotalPrice
)Insert the code snippet provided below after the determinations as shown on the screenshot.
//side effects for a target entity side effects { field FlightPrice affects field _Travel . TotalPrice; field CurrencyCode affects field _Travel . TotalPrice; }
Now, you have to expose the side effects in the BO behavior projection to enable it on the Fiori elements Travel app.
🔵 Click to expand!
9.3 - Define Side Effects in the Travel BO Projection
Now, you will define side effects in the BO behavior projection for the virtual elements defined in the BO projection view:
DaysToFlightIndicator
,InitialDaysToFlight
, andRemainingDaysToFlight
.Side effects for elements defined the BO projection layer have to be defined on the same layer. They cannot be defined on the base BO layer.
🔵 Click to expand!
-
Go to the behavior projection of the Travel BO
ZRAP110_C_TravelTP_###
. -
Insert the code snippet provided below in the behavior projection of the booking BO entity
ZRAP110_C_BookingTP_###
just after theuse delete;
statement as shown on the screenshot.side effects { field BookingDate affects field DaysToFlightIndicator, field InitialDaysToFlight, field RemainingDaysToFlight; field FlightDate affects field DaysToFlightIndicator, field InitialDaysToFlight, field RemainingDaysToFlight; field ConnectionID affects field DaysToFlightIndicator, field InitialDaysToFlight, field RemainingDaysToFlight; field CarrierID affects field DaysToFlightIndicator, field InitialDaysToFlight, field RemainingDaysToFlight; }
You can now preview and test the changes by creating a new travel instance with booking instances in the Travel app.
🔵 Click to expand!
-
Refresh your application in the browser using F5 if the browser is still open -
or go to your service bindingZRAP110_UI_TRAVEL_O4_###
and start the Fiori elements App preview for theTravel
entity set. -
For example, go to an existing Travel instance or edit an existing one, and change either the booking fee or a booking flight price.
The total price should be re-calculated directly.
Now that you've...
- defined side effects in the base BO,
- exposed them in the BO projection, and
- tested the enhanced Travel app,
you can continue with the next exercise – Exercise 10: Implement the Base BO Behavior - Functions