cancel
Showing results for 
Search instead for 
Did you mean: 

Add multiple associated entity values to CDS entity projection / Fiori annotation

tono
Discoverer
0 Kudos

Dear SAP-Community,

I'm trying to model a bookshop with the entities Books and Authors:

entity Books {
    key guid              : UUID;
        title             : String(20);
        stock             : Integer;
        year              : String(4);
        author            : Association to Authors;
        edition           : String;
}

entity Authors {
    key guid              : UUID;
        firstName         : String(30);
        lastName          : String(20);
        born              : Integer;
        books             : Association to many Books
                                on books.author = $self;
}

I want to display the full name of the author in one or two columns in an Fiori Elements App.

For the app I have the following service:

using my.bookshop as my from '../db/data-model';

@path: 'service/books'
service CatalogService {
    entity Books as projection on my.Books
    {
        key guid,
        title,
        stock,
        year,
        author,
        edition
    };
    entity Authors as projection on my.Authors;
}

And the following annotations:

using CatalogService as CatService from '../srv/cat-service';

annotate CatService.Books with @(
    UI: {
        HeaderInfo  : {
            TypeName : '{i18n>Books.TypeName}',
            TypeNamePlural : '{i18n>Books.TypeNamePlural}',
            Title : { $Type: 'UI.DataField', Value: title },
        },
        SelectionFields  : [ title, stock, year ],
        LineItem  : [
            {$Type: 'UI.DataField', Value: guid, @UI.Hidden},
            {$Type: 'UI.DataField', Value: author_guid},
            {$Type: 'UI.DataField', Value: title},
            {$Type: 'UI.DataField', Value: year},
            {$Type: 'UI.DataField', Value: edition},
            {$Type: 'UI.DataField', Value: stock}
        ],
    },
);

annotate CatService.Books with {
    author @(Common : { 
        Text: author.lastName,
        TextArrangement : #TextOnly,
        ValueList : {
            Label: 'Autor',
            $Type : 'Common.ValueListType',
            CollectionPath : 'Authors',
            Parameters: [
                {
                    $Type: 'Common.ValueListParameterInOut',
                    LocalDataProperty: author_guid,
                    ValueListProperty: 'guid'
                },
                {
                    $Type: 'Common.ValueListParameterDisplayOnly',
                    ValueListProperty: 'lastName'
                }
            ]
        },
     })
};

// Properties Object Page
annotate CatService.Books with @(UI : {
    Facets           : [{
        $Type  : 'UI.ReferenceFacet',
        Label  : title,
        Target : '@UI.FieldGroup#Main',
    }],
    FieldGroup #Main : {Data : [
        {Value : author_guid},
        {Value : title},
        {Value : stock},
        {Value : edition},
        {Value : year}
    ]},
});

annotate CatService.Books with {
    //ID @( Common: { Label: '{i18n>Books.ID}'});
    title @( Common: { Label: '{i18n>Books.title}'});
    stock @( Common: { Label: '{i18n>Books.stock}'});
    year @( Common: { Label: '{i18n>Books.year}'});
    author @( Common: { Label: '{i18n>Books.author}'});
    edition @( Common: { Label: '{i18n>Books.edition}'});
};

I don't know how to add the firstName to the author annotation.

Thanks for your help!

- Anton


Accepted Solutions (1)

Accepted Solutions (1)

gregorw
Active Contributor
0 Kudos

I would suggest you have a look at the sample app: fiori/app/common.cds

tono
Discoverer
0 Kudos

Thank you!

For anyone looking this up, this is how you access the keys of entities:

LineItem  : [
	{$Type: 'UI.DataField', Value: author.firstName, Label: '{i18n>author.firstName}'},
	{$Type: 'UI.DataField', Value: author.lastName, Label: '{i18n>author.lastName}'},
]

Answers (0)