In this topic, we explain how to provide value help for your Fiori app based on the foreign key associations approach.
The following figure depicts the components involved and the development activites that are required to provide - from scratch - the value help option based on the foreign key relationship.
The language field is annotated with @Semantics.language: true.
The relationship between a field and its language-dependent descriptive text field(s) is established by using an annotation @ObjectModel.text.association.
The following set of CDS annotations is relevant when defining text views:
The annotations at view level are:
Annotation and Value |
Effect |
---|---|
@ObjectModel.dataCategory: #TEXT |
Indicates that the annotated CDS view represents
texts (defines a text view)..
Note One key element
is used to specify the language.
|
@ObjectModel.representativeKey: '<name>' |
For text views, the <name> identifies the key element to which the text fields refer. |
@Search.searchable: true |
This annotation is necessary to define that the search function is supported. |
The annotations (required) on the field level are:
Annotation and Value |
Effect |
---|---|
@Semantics.language: true |
The annotated field identifies the language. |
@Semantics.text: true |
Identifies fields as text fields (fields holding a textual description). |
@Search.defaultSearchElement: true |
Denotes that it is possible to search for the annotated field in the freestyle search field on the value help dialog. |
@Search.fuzzinessThreshold: <value> |
Defines how fuzzy the text search applied to the annotated field should be. For example, the value 0.8 refers to a similarity of 80%. |
Example:
The listing below implements a sample text view. Its entity is named ZDEMO_I_Text and uses a database table T006A as its data source. Each text field needs to be annotated with @Semantics.text: true. In this example, only the field MSEHT (Name) is displayed as a text field on the value help dialog screen. The annotations @Search.searchable: true and @Search.defaultSearchElement: true are necessary to define that the search function is supported. This means that a freestyle search field appears on the value help UI where it is possible to search for the text field (Name). The annotation @Search.fuzzinessThreshold: 0.8 defines that the text search should be applied to this element with a similarity value of 80%.
@AbapCatalog.sqlViewName: 'ZDEMO_I_T' @ObjectModel.dataCategory: #TEXT @ObjectModel.representativeKey: 'UnitOfMeasure' @Search.searchable: true define view ZDEMO_I_Text as select from t006a as TextProvider { key TextProvider.msehi as UnitOfMeasure, @Semantics.language: true -- identifies the language key TextProvider.spras as Language, @Semantics.text: true -- identifies the text field @Search.defaultSearchElement: true @Search.fuzzinessThreshold: 0.8 TextProvider.mseht as Name }
The following set of CDS annotations is relevant when defining value help views that serve as consumer of a text view:
The annotations (required) at view level are:
Annotation and Value |
Effect |
---|---|
@Search.searchable: true |
These annotations are necessary to define that the search function is supported. |
@EndUserText.label: '<text>' |
This annotation specifies the heading text that will be visible in the value help dialog. |
The annotations (required) on the field level are:
Annotation and Value |
Effect |
---|---|
@ObjectModel.text.association: '<_AssocToTextProvider>' |
Name of an association to a text view, which provides descriptive texts for the annotated field. |
@Search.defaultSearchElement: true |
This annotation denotes that it is possible to search for the annotated field in the freestyle search field on the value help dialog. |
Example:
In the following example, the CDS view ZDEMO_I_ValueHelp selects the values for the value help from DB table T006. The annotation @EndUserText.label: 'Unit of Measure Value Help' provides a text that will be displayed in the heading of the value help dialog. The annotations @Search.searchable: true and @Search.defaultSearchElement: true are necessary to define that the search function is supported. This means that a freestyle search field appears on the value help UI where it is possible to search in the content of the field UnitOfMeasure and its description. The annotation @ObjectModel.text.association: '_Text' describes an association that points to the text view ZDEMO_I_Text, which contains the text fields to be displayed in the value help dialog.
@AbapCatalog.sqlViewName: 'ZDEMO_I_VH' @Search.searchable: true @EndUserText.label: 'Unit of Measure Value Help' define view ZDEMO_I_ValueHelp as select from t006 as ValueProvider association [0..*] to ZDEMO_I_Text as _Text on $projection.UnitOfMeasure = _Text.UnitOfMeasure { @ObjectModel.text.association: '_Text' @Search.defaultSearchElement: true key msehi as UnitOfMeasure, -- association _Text }
To enable value help in the Fiori app, the following two additions in the consumer view are required:
a. First, add the association to the value help provider view that contains the value list.
b. Then add the annotation @ObjectModel.foreignKey.association to the field for which a value help should be made available.
The annotation (required) on the field level:
Annotation and Value |
Effect |
---|---|
@ObjectModel.foreignKey.association: '<_AssocToValueHelpProvider>' |
The annotation assigns the association
‘_AssocToValueHelpProvider’ to
the given view field: The association’s target view
serves as a value help provider and is used to
retrieve the values of the value help.
Note The maximum target cardinality of the
association has to be 1.
|
Example:
The consumer view ZDEMO_C_ValueHelp_Demo in the listing below defines a data model for sales order items. Here, the association _QuantityUnitValueHelp with the target view that represents a value list for quantity units (ZDEMO_I_ValueHelp) is also defined. This association defines a foreign key relationship for the annotated field Document.QuantityUnitCode. At runtime, the annotated field must be valuated as equal to the annotated representative key element of the target view.
... define view ZDEMO_C_ValueHelp_Demo as select from SalesOrderItem as Document /* Association to quantity unit value help provider */ association [0..1] to ZDEMO_I_ValueHelp as _QuantityUnitValueHelp on $projection.QuantityUnitCode = _QuantityUnitValueHelp.UnitOfMeasure ... { /* Field list */ ... @Semantics.unitOfMeasure: true @ObjectModel.foreignKey.association: '_QuantityUnitValueHelp' Document.QuantityUnitCode, ... /* List of associations */ ... _QuantityUnitValueHelp }
Create either an OData service automatically by adding the annotation @OData.publish: true into the consumer view or manually using the SEGW transaction. In the latter case, you must expose the association to the value help provider view.
More on this: Generating an OData Service Based on a CDS ViewIf you run the sales order app, the annotated input field displays a value help icon.
When you call the value help dialog, it displays the key and text fields that are specified in the value help text view