cancel
Showing results for 
Search instead for 
Did you mean: 

CAP: Getting Enum Values from OData Service

Domae
Participant

Hey guys,

I have a CAP entity "Books" with a Property "Status", which is exposed via an Node.js OData V4 Service and which is defined with some enumeration values like this:

entity Books {
    key ID     : Integer;
        title  : localized String;
        author : Association to Authors;
        stock  : Integer;
        status                : String(1)
        @( title: 'Status', ) enum {
          requested = 'R' @( title: 'Requested');
          pending   = 'P' @( title: 'Pending');
          approved  = 'A' @( title: 'Approved');
          rejected  = 'N' @( title: 'Rejected');
      };
}

The entries of the "Books" entity look like this:

ID;title;author_ID;stock;status
201;Wuthering Heights;101;12;P
207;Jane Eyre;107;11;A
251;The Raven;150;333;A
252;Eleonora;150;555;N
271;Catweazle;170;22;P

Now when I read the Books entity from my Fiori Elements List Report I want to have the titles of the "status" property and not only the 1 length characters.

Is this even possible?

Best Regards

Dominik

View Entire Topic

Hi Dominik,

if you want status names to be displayed in Fiori, having them as symbol names in an enum is not sufficient. You need to define a dedicated entity for that purpose.

As an example, have a look at our SFLIGHT sample app at https://github.com/SAP-samples/cap-sflight.

In https://github.com/SAP-samples/cap-sflight/blob/main/db/schema.cds there are the entities "BookingStatus" and "TravelStatus". Their key is the status code (modelled as enum), but via the aspect "CodeList" they also get a "name". These entities are used for the status fields of entities "Booking" and "Travel", respectively.

For display, annotation "@Common.Text" is used to show the status name instead of the code: https://github.com/SAP-samples/cap-sflight/blob/main/app/travel_processor/labels.cds#L15 and https://github.com/SAP-samples/cap-sflight/blob/main/app/travel_processor/labels.cds#L33.

inu2200
Newcomer
0 Kudos

Hi @steffen_weinstock,

thanks for your solution. However, the scripts in the repo for showing the Status name are no longer available. May I ask you to share the original files, please? >"<