on 05-19-2021 10:17 AM
We have a CAP Java project and are building a Fiori Elements UI via CDS annotations.
We would like to provide a Value Help for one of the filter options on our List Report page.
The entity looks like this:
type ChangeEventType : String enum {
Created;
Updated;
Deleted;
};
entity ChangeLogs : cuid {
occuredAt : Timestamp;
eventType : ChangeEventType;
...
}
From my understanding of the documentation (https://github.wdf.sap.corp/pages/cap/advanced/fiori#value-help-support) value help is only supported for Entities or CodeLists.
How would I add a value help via cds annotations for a type Enum property?
Hi Lena,
For providing a value help in Fiori elements, you always require a ValueList annotation on the corresponding entity property. The ValueList annotation contains property 'CollectionPath' pointing to the values providing entity. So, from a service $metadata perspective, there is no codelist, but entities with properties.
In CAP, defining an entity based on aspect CodeList only generates the ValueList annotation for you at CDS compilation, and it also contains the collection path pointing to the codelist based entity that is exposed with the service.
This gets more clear if you look at the existing ValueList Annotations of your service's metadata.
Explanation with example can be found here:
https://github.com/SAP-samples/fiori-elements-feature-showcase/blob/main/README.md#value-help
For your use case, I would recommend to put an enum typed property inside an aspect of type CodeList (and put a Text with TextArrangment annotation in there so that the name is shown instead of the code), and then use it in an VH entity and for your ChangeLogs entity.
Like this you get the ValueList Annotation for free.
You can btw. override the default ValueList Annotation by simply defining it again explicitely.
Without having tested it, your code would look somthing like this:
aspect ChangeEvents : CodeList { @( Common : { Text : name, TextArrangement : #TextOnly } ) key code : String enum { Created = 'C'; Updated = 'U'; Deleted = 'D'; }};
entity ChangeEvent: ChangeEvents {};
entity ChangeLogs : cuid, ChangeEvents { occuredAt: Timestamp;}
annotate ChangeLogs with { code @(Common : { Text : name, TextArrangement : #TextOnly, ValueList : { Label : '{i18n>ChangeEvent}', CollectionPath : 'ChangeEvent', Parameters : [ { $Type : 'Common.ValueListParameterInOut', ValueListProperty : 'code', LocalDataProperty : code }, { $Type: 'Common.ValueListParameterDisplayOnly', ValueListProperty: 'name', } ] } });};
Hope that helps.
Best regards
Christian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
77 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.