SAP Guide: Add a Fiori Elements App to a CAP Service

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-13 against CAP Node.js 10.2 (@sap/cds 10.2.2, @sap/cds-dk 10.2.1), the Fiori elements preview of cds watch (it loads SAPUI5 1.145.0) and Node.js 24.21.

What you build

This is a teaching model built with CAP. It is not SAP S/4HANA or SAP SuccessFactors and does not reproduce their screens.

You give the expenses service of the guide Your First CAP Service a user interface without writing any UI code. You write annotations, short pieces of metadata next to the service, and the Fiori elements preview of cds watch builds two pages from them: a list report that shows all claims in a table, and an object page that shows one claim. You switch a claim to a draft to edit it, add a value help that lets the user pick a status from a list, and create a second claim.

Fiori elements list report with two claims: Train ticket with the status A and the amount 50.00, and Taxi with the status N and the amount 18.00

Before you start

  • No account is needed: the preview is part of the CAP tools that you installed without signing in. It loads the SAPUI5 libraries from a public content delivery network, so the computer needs internet access. Installing @sap/cds-dk means accepting the SAP Developer License Agreement, version 3.2, which the lab README names.

  • Do the guide Your First CAP Service first. You need its project expenses with db/schema.cds, srv/expense-service.cds and the CSV file, and cds watch must work.

  • Read SAP Fiori Elements for the idea of the floorplans and annotations, and SAP Fiori Design Guidelines for the design rules behind the pages.

  • The preview takes its language from the browser. Add sap-language=EN to the address, as in step 5, to get the English texts of this guide.

  • The figures are drawings of the pages, not screenshots, so small details can differ from your screen. A highlighted box with a number marks the part of the page that the step with the same number deals with.

Steps

The two numbered overviews show the pages that the preview builds. The list report is the start page: a filter bar above a table. The object page opens when you click a row.

Map of a Fiori elements list report with seven numbered regions: the shell bar, the variant name, the filter fields, Go, Adapt Filters, the table toolbar with Create and Delete, and the table of claims
Map of a Fiori elements object page with five numbered regions: the header title, the Edit and Delete actions, the section tabs General and Administration, the section card and the fields with their labels

Prepare the service and the labels

  1. Open srv/expense-service.cds and put @odata.draft.enabled above the entity line. It tells CAP to keep a draft copy of a claim while someone edits it, which the object page needs for its Edit button. The file now reads:

    using { sap.guide.expenses as db } from '../db/schema';
    service ExpenseService {
      @odata.draft.enabled
      entity Claims as projection on db.Claims;
    }
  2. Create the folder app (it already exists after cds init) and in it the file app/annotations.cds. The first line imports the service. The annotation gives each field a label, which the pages show above the values; without it they show the bare values.

    using ExpenseService as service from '../srv/expense-service';
    
    annotate service.Claims with {
      title  @title : 'Title';
      status @title : 'Status';
      amount @title : 'Amount';
    };
    Visual Studio Code with the expenses project: the explorer lists app/annotations.cds and srv/expense-service.cds, the editor shows annotations.cds with the line that imports ExpenseService and the annotation that gives the fields title, status and amount their labels; callout 1 marks the service file and callout 2 marks the annotation file

Show the list report

  1. Add the annotation UI.LineItem to app/annotations.cds. It lists the fields that become the columns of the table, in this order:

    annotate service.Claims with @(
      UI.LineItem : [{ Value : title }, { Value : status }, { Value : amount }]
    );
  2. In the terminal, in the project folder, start the server (or leave it running: cds watch reloads when you save):

    cds watch
  3. Open http://localhost:4004/$fiori-preview/ExpenseService/Claims?sap-language=EN#preview-app. The welcome page at http://localhost:4004 offers the same page behind the link Fiori preview next to the entity Claims. The page is a list report: a filter bar with a search field and Editing Status, the buttons Go and Adapt Filters, and the table Claims (1) with the columns Title, Status and Amount and your claim.

    Fiori elements list report of the Claims preview: the shell bar title is marked by callout 5 and the table with the columns Title, Status and Amount, which come from the line item annotation, is marked by callout 3; one claim, Train ticket with status N and amount 45.50, is listed

Describe the object page

  1. Add the annotation UI.HeaderInfo. Its Title names the field that the object page shows as its large title, and TypeName and TypeNamePlural name what one and many rows are called:

    annotate service.Claims with @(
      UI.HeaderInfo : { TypeName : 'Claim', TypeNamePlural : 'Claims', Title : { Value : title } }
    );
  2. Add the annotations UI.Facets and two field groups. A facet is a section of the object page, here General and Administration, and each points to a field group, the list of fields that the section shows. The fields createdAt, createdBy, modifiedAt and modifiedBy come from the aspect managed of the first guide.

    annotate service.Claims with @(
      UI.Facets : [
        { $Type : 'UI.ReferenceFacet', Label : 'General', Target : '@UI.FieldGroup#General' },
        { $Type : 'UI.ReferenceFacet', Label : 'Administration', Target : '@UI.FieldGroup#Admin' }
      ],
      UI.FieldGroup #General : { Data : [{ Value : title }, { Value : status }, { Value : amount }] },
      UI.FieldGroup #Admin : { Data : [{ Value : createdAt }, { Value : createdBy }, { Value : modifiedAt }, { Value : modifiedBy }] }
    );
  3. Click the row Train ticket in the list. The object page opens with the title, the buttons Edit and Delete, the tabs General and Administration, and one card per section with the fields and their labels.

    Fiori elements object page of the claim Train ticket: the header title is marked by callout 6, the tabs General and Administration by callout 7, and the General section with the fields Title, Status and Amount by callout 8; Edit and Delete are in the header

Edit a claim as a draft

  1. Click Edit. The page becomes a draft: a marker Draft appears next to the title, a Header tab and section with the title field are added, the fields become input fields, and a footer bar shows Save and Discard Draft. Nothing is stored in the real claim yet; CAP keeps the changes in the draft.

  2. Change the Amount to 50.00. The footer shows Draft updated as soon as you leave the field. Click Save. A message Object saved appears, and the object page shows the new amount; the field Changed On has a new time.

    Fiori elements object page of the claim in edit mode: next to the title the marker Draft is marked by callout 9, an extra Header tab and section appear, the Amount field holds 50.00 and the footer shows Draft updated with the buttons Save, marked by callout 10, and Discard Draft

Add a value help for the status

The status field accepts any letter. A value help lets the user pick from a list of allowed statuses. The list is an entity of its own.

  1. In db/schema.cds, add the entity Statuses with a key code and a name, and create the CSV file db/data/sap.guide.expenses-Statuses.csv with four rows:

    entity Statuses {
      key code : String(1);
      name     : String(20);
    }
    code,name
    N,New
    A,Approved
    R,Rejected
    P,Paid
  2. In srv/expense-service.cds, add the entity to the service, below Claims. @readonly lets users read the list but not change it:

      @readonly
      entity Statuses as projection on db.Statuses;
  3. In app/annotations.cds, annotate the field status with Common.ValueList. CollectionPath names the entity set that holds the allowed values. The first parameter links the field status of the claim (LocalDataProperty) to the column code of the list and writes the chosen code back into the field; the second shows the name column as information:

    annotate service.Claims with {
      status @Common.ValueList : {
        CollectionPath : 'Statuses',
        Parameters : [
          { $Type : 'Common.ValueListParameterInOut', LocalDataProperty : status, ValueListProperty : 'code' },
          { $Type : 'Common.ValueListParameterDisplayOnly', ValueListProperty : 'name' }
        ]
      };
    };
  4. Reload the preview, open the claim, click Edit and click the value help icon at the end of the Status field. The dialog Select: Status lists the four statuses, sorted by code. Click the row Approved: the field shows A. Click Save.

    The value help dialog Select: Status over the claim in edit mode: a search field with Go and Show Filters, then Items (4) with the codes and names A Approved, N New, P Paid and R Rejected, and a Cancel button; callout 14 marks the row Approved

Create a claim

  1. Go back to the list with the arrow in the shell bar and click Create. A new draft opens with the status N, which is the default of the model. Type Taxi as the Title and 18.00 as the Amount, then click Create in the footer. The new claim appears in the list.

    Fiori elements object page for a new claim titled Taxi with the status N and the amount 18.00; the footer shows Draft updated with the buttons Create, marked by callout 15, and Discard Draft

Check the result

What can go wrong

Symptom Cause Fix

The object page shows only values, with no labels above them

The fields have no label, because the annotation of step 2 is missing.

Add the annotation of step 2 and reload the page.

The texts are not in English

The preview takes its language from the browser.

Add sap-language=EN to the address, as in step 5.

Clean up

Press Ctrl+C in the terminal to stop cds watch. The database lived only in memory, so the claim Taxi and the changes are gone at the next start; the CSV files bring back the starting data.

Where to go next