
RAP - Popup Default values
How can you provide the user with default values in the popup of an action in RAP? In this article we will extend our application.
Table of contents
In the last article, we expanded the popup in our application to include mandatory fields that are checked in the UI. In this article, we'll look at defining default values in the popup.
Introduction
When a user triggers an action in the Fiori Elements UI, you usually want to have some information from the user. To make life easier for the user, you can also provide default values in many situations so that the user receives suggestions for input and thus works faster. To do this, we will extend our Report Pattern app with another function.
Extension
In this section, we will extend our existing action and implement the logic for the values. Finally, we will run a test to validate the result.
Behavior definition
To do this, we will extend our current definition of the "LoadExcelContent" action in the behavior definition. We are currently using a simple action with a parameter, which ensures that a popup is displayed when triggered.
action LoadExcelContent parameter ZBS_S_DRPExcelPopup;
To do this, we add DEFAULT FUNCTION in curly brackets to define a new function in which we can set the default values.
action LoadExcelContent parameter ZBS_S_DRPExcelPopup { default function GetDefaultsForExcelPopup; }
The name of the function must begin with "GetDefaultsFor" or "GetDfltsFor". Here you already get the information
Behavior implementation
If you place the cursor on the name of the function, you can use CTRL + 1 to generate the method in the behavior implementation. Let's take a look at the signature of the new method.
We receive the keys of the currently selected entries and can return our values via RESULT. There, next to the key, you will find the %PARAM field, where our parameter structure is defined. To do this, we define a small logic that defines a standard for the comment with the current currency. In addition, the test run flag should always be set for the currency EUR.
LOOP AT keys INTO DATA(key).
INSERT VALUE #( %tky = key-%tky ) INTO TABLE result REFERENCE INTO DATA(new_line).
new_line->%param-EventComment = |Default event for { key-Currency }|.
new_line->%param-TestRun = SWITCH #( key-Currency
WHEN 'EUR'
THEN abap_true
ELSE abap_false ).
ENDLOOP.
Projection
Now comes the most important step. So that the function can be called from the frontend, we have to release it in the projection of our RAP object to the outside. In this case, it is not an action, but a function. Accordingly, the implementation looks like this:
use function GetDefaultsForExcelPopup;
Test
Now that we have everything prepared, we can carry out the test in our application. To do this, we open the currency EUR and trigger the action. You can see the result here.
Complete example
You can find the complete application in our GitHub repository, we have made the changes to this article in the following commit. There you will find all changes and changed objects at a glance.
Conclusion
Setting the default values is easy and flexible with the function, but you also have to implement some logic rather than just a simple assignment. The user will now be able to work with your application faster.
Source:
SAP Help - Defaulting Input Parameters for Operations
SAP Community - Defaulting action parameters