cancel
Showing results for 
Search instead for 
Did you mean: 

How to select multiple authors in a SAP CAP Fiori Elements app?

truckla
Explorer
0 Kudos
126

Hi

I’m building a SAP CAP application for managing books and authors.
I followed some examples and tried to recreate them step-by-step.
Currently, my app looks like what you can see in the attached screenshots.

When I open the Fiori preview for "Books", I can see all books.
If I click on a book, the detail page opens, and I can edit it, so far, everything works as expected.

Now my question:
How can I select multiple authors in the detail page instead of just one?
I can't find a way to make this possible.

Do I need to change the relationship between the entities for this to work?

I would like to stick to the standard as much as possible and implement everything using annotations rather than modifying the .js files.

Below you can find my schema.cds and service.cds.
service.cds:

 

using { sap.capire.bookshop as my } from '../db/schema';

service BookshopService @(path: '/browse') {
  @readonly entity Books as projection on my.Books {
    *,
    author.name as authorName
  };
}

service AdminService @(path: '/admin') {
  entity Books as projection on my.Books;
  entity Authors as projection on my.Authors;
}

annotate AdminService.Books with @(
  UI: {
    HeaderInfo: {
      TypeName: 'Buch',
      TypeNamePlural: 'Bücher',
      Title: { Value: title },
      Description: { Value: author.name }
    },
    SelectionFields: [ title, author_ID, price ],
    LineItem: [
      { Value: title, Label: 'Titel' },
      { Value: author.name, Label: 'Autor' },
      { Value: stock, Label: 'Lagerbestand' },
      { Value: price, Label: 'Preis' },
      { Value: currency.symbol, Label: 'Währung' }
    ],
    Facets: [
      {
        $Type: 'UI.CollectionFacet',
        Label: 'Details',
        Facets: [
          {
            $Type: 'UI.ReferenceFacet',
            Label: 'Allgemeine Informationen',
            Target: '@UI.FieldGroup#General'
          }
        ]
      }
    ],
    FieldGroup#General: {
      Data: [
        { Value: title, Label: 'Titel' },
        { Value: author_ID, Label: 'Autor' },
        { Value: stock, Label: 'Lagerbestand' },
        { Value: price, Label: 'Preis' },
        { Value: currency_code, Label: 'Währung' },
        { Value: description, Label: 'Beschreibung' }
      ]
    }
  }
);

annotate AdminService.Authors with @(
  UI: {
    HeaderInfo: {
      TypeName: 'Autor',
      TypeNamePlural: 'Autoren',
      Title: { Value: name }
    },
    SelectionFields: [ name ],
    LineItem: [
      { Value: name, Label: 'Name' },
      { Value: dateOfBirth, Label: 'Geburtsdatum' }
    ],
    Facets: [
      {
        $Type: 'UI.CollectionFacet',
        Label: 'Details',
        Facets: [
          {
            $Type: 'UI.ReferenceFacet',
            Label: 'Allgemeine Informationen',
            Target: '@UI.FieldGroup#General'
          },
          {
            $Type: 'UI.ReferenceFacet',
            Label: 'Bücher',
            Target: 'books/@UI.LineItem'
          }
        ]
      }
    ],
    FieldGroup#General: {
      Data: [
        { Value: name, Label: 'Name' },
        { Value: dateOfBirth, Label: 'Geburtsdatum' }
      ]
    }
  }
);

annotate AdminService.Books with @odata.draft.enabled;
annotate AdminService.Authors with @odata.draft.enabled;

annotate AdminService.Books {
  author @(
    Common: {
      Text: {
        $value: author.name,
        ![@UI.TextArrangement]: #TextOnly
      },
      ValueList: {
        entity: 'Authors',
        type: #fixed
      }
    }
  );
}

 

schema.cds:

 

namespace sap.capire.bookshop;

using { Currency, managed } from '@sap/cds/common';

entity Books : managed {
  key ID       : UUID @(Core.Computed : true);
  title        : String(100) @title: 'Titel';
  author       : Association to Authors @title: 'Autor';
  stock        : Integer @title: 'Lagerbestand';
  price        : Decimal(9,2) @title: 'Preis';
  currency     : Currency @title: 'Währung';
  description  : String(1000) @title: 'Beschreibung';
}

entity Authors : managed {
  key ID       : UUID @(Core.Computed : true);
  name         : String(100) @title: 'Name';
  dateOfBirth  : Date @title: 'Geburtsdatum';
  books        : Association to many Books on books.author = $self;
}

 

 

Testdata csv:

 

ID,name,dateOfBirth
3b22d8e3-01df-44d3-8ee7-6126a05ad547,Max Mustermann,1970-01-01
8c3a4cce-7c20-4d40-839d-80ec4e5f1df2,Erika Musterfrau,1985-03-15
9e3844b1-bff7-4a56-9f46-1acbaee2f1a7,Johann Wolfgang von Goethe,1749-08-28
ID,title,author_ID,stock,price,currency_code,description
7f03a0b3-ce3d-4a5e-8da0-67a7f1fef2e6,Der Buchshop,3b22d8e3-01df-44d3-8ee7-6126a05ad547,100,19.99,EUR,Ein spannendes Buch über einen Buchshop
60ad0b9c-b3d8-45b9-a318-0c50a7b35fed,Der Programmierer,8c3a4cce-7c20-4d40-839d-80ec4e5f1df2,50,29.99,EUR,Ein Buch über die Herausforderungen des Programmierens
84eef739-3c7e-4af9-b32c-cbdc47ab6bc2,Faust,9e3844b1-bff7-4a56-9f46-1acbaee2f1a7,75,15.99,EUR,Ein Klassiker der deutschen Literatur

 

 

View Entire Topic
junwu
SAP Champion
SAP Champion
0 Kudos

multiple value means a new table

you author has to be a table/sub node of the book.

truckla
Explorer
0 Kudos
Do you have an example for me? Unfortunately, I'm still very new and don't know much about it
junwu
SAP Champion
SAP Champion
0 Kudos
you can move on if it is probably too much for a new guy, you just need to have the concept, one db column/field can only hold one value, if you want mutiple value for one field, that "field" needs to be a table
junwu
SAP Champion
SAP Champion
0 Kudos