SAP Fiori CDS Annotations (II): How to Expand Selection Field With Value Help

SAP Fiori CDS Annotations (II): How to Expand Selection Field With Value Help

Continuing the series of CDS annotations. Take a look at our previous article: Sap CDS Annotations (I): How to Implement Fiori CDS Annotations in List Report.

Today we are going to see another basic and fundamental annotation for the implementation of our List Reports. We will learn how to expand selection field with valouehelp.

The template offered by SAP Web IDE for developing a List Report makes our application design development work much easier and faster. However, to meet requirements or improve the application, we can extend the functionality through our CDS annotations.

One of the most important functionality in a List Report type is the filtering that is carried out on it through the selection fields. Today we are going to learn how to configure these selection fields through CDS annotations.

Implement Selection field

In our main CDS view, we expose different fields to display in our application. With the @ui.selectionField annotation we can easily indicate which fields can be filtered in our List Report.

In our example, we have two selection fields: material and description. As we can see, before exposing the field, it is indicated through the @ui.selectionField annotation that these fields will be used to filter, indicating a position that will represent the order in which they are displayed in our header.

If we click on one of our selection fields, we initially have a basic filter where we can search for the article by a single specific field, as we can see in the image:

This functionality is useful and allows us to filter the list by the item we want. However, the objective of an application is that it is the most usable and agile for the user to use, and for this there are annotations that allow us to optimize searches and combine different filtering fields.

Enrich Selection Field With Value Help via CDS Annotations

Streamlining the life of the user is essential in the development of an application, and with this example, we are going to see how we can allow the user to make combined filters to find the item they need more easily.

The first step is to create a CDS view that will be in charge of retrieving the filtering data in our article search aid. To do this, we need to retrieve the list of materials along with its description:

It is important that we define the fields as “searchable” through the @Search.defaultSearchElement annotation. This will allow us, as we will see later, to perform quick searches by code or article description, without having to click on the search help. Finally, we must indicate in our main CDS that the article field is associated with a search aid, in our case, ZCDS_VALUEHELP_MATERIAL:

Through the @Consumption.valueHelpDefinition annotation we can associate a custom search help with a field. Within this definition, we can indicate how many fields we allow to filter from among those exposed in the CDS view of the search aid. In this example, I have selected the ‘Material’ field and the ‘Description’ field.

We activate our CDS views and return to our application. Now, if we click on our search aid again, we can see that it is already possible to filter by the two fields indicated in the annotation:

Furthermore, by indicating in our CDS view defined for search aid that the exposed fields were ‘searchable’ through the @Search.defaultSearchElement annotation, if we type directly over our Article selection field, we will see the following happen:

Facilitating the user’s work is essential for any Fiori application project in a client to generate an increase in the productivity of the process it covers. With just two CDS annotations, we allow the user to quickly search for an article directly in its corresponding selection field, as well as combine article searches as desired, allowing more flexibility for the user.

Leave a Reply