Skip to content

1. The UI First ​

The first step changes nothing on the server. Your SAP CAP service keeps serving OData; Atscript OData reads its $metadata, generates Atscript models, and Atscript UI renders the new screens from them. Existing SAP Fiori® apps keep working next to the new screens, against the same service.

 SAP CAP service (OData v4) ──► Atscript OData ──► Atscript UI screens
                           └──► existing Fiori apps, unchanged

Generate the models ​

Save the service's $metadata (SAP CAP serves it at /odata/v4/<service>/$metadata):

bash
npx atscript-odata fetch 'http://localhost:4004/odata/v4/catalog/$metadata' \
  --out src/odata/catalog.xml --language en

Add --user / --password or --header "Authorization: …" when the service requires a login. --language names the language the labels are read in, at build time and when the hosts read the live $metadata at runtime (see Live Metadata). Then register it with the plugin:

ts
// atscript.config.ts
odataPlugin({
  services: [{ name: "catalog", metadata: "odata/catalog.xml" }],
});

Every build now writes src/odata/catalog.as and src/odata/catalog.model.gen.ts. Generating Models explains the files and the options.

What an SAP CAP service gives you ​

The generator reads what SAP CAP writes into the $metadata:

In your .cds modelIn the generated .as
entities exposed by the serviceone interface per entity set, with @db.table
key elements@meta.id
cuid keys@db.default.uuid: a create may leave the key out
@title, @Common.Label@meta.label
String(n), Decimal(p,s)@expect.maxLength, @db.column.precision
@readonly elements, @Core.Computed@meta.readonly, with @db.default.store on a scalar
managed (createdAt, createdBy, …)read-only fields the service fills (@meta.readonly, @db.default.store)
@Common.ValueList@ui.valueHelp with fills and columns (Value Helps)
@Common.Text with @UI.TextArrangement@ui.valueLabel; on the text of a single key also @ui.dict.label
associations and compositionsrelations, loaded with $with (Relations)
@odata.etagthe version token __etag (Writes)

What stays on the server: the @assert.* checks and your handlers. They still run on every write; when they refuse one, the service's 400 messages reach the fields of the form they name (see Errors).

The @UI annotations of Fiori elements (line items, field groups, facets) are not read: lay out the Atscript UI screens with @ui.table.* and @ui.form.* in annotate blocks of your own (see Enrich the generated types).

An SAP CAP service is recognized as such, and gets the standard dialect by itself (see Dialects).

Drafts and actions ​

Two things an SAP CAP app often uses work only partly:

  • Draft-enabled entities (@odata.draft.enabled) are read and listed for their active entities, and take no write (planned). The new screens can list and show them; keep editing them in the existing app for now.
  • Actions and functions are db actions on both hosts: a Moost server serves them through generated base classes, the browser client lists and calls the live service's by itself (see Operations); several rows go out as one $batch, as in Fiori Elements.

See Limitations.

Build the screens ​

Pick the host as the Overview describes:

Browser client. Register the service, and the screens address its entity sets as /odata/catalog/<EntitySet>:

ts
// src/main.ts
import { createODataClientFactory } from "@atscript/odata-client";
import { setDefaultClientFactory } from "@atscript/ui";
import { createApp } from "vue";
import App from "./App.vue";
import * as catalog from "./odata/catalog.as";
import { model } from "./odata/catalog.model.gen";

const odata = createODataClientFactory({
  services: [{ baseUrl: "/odata/v4/catalog", model, types: catalog }],
});
setDefaultClientFactory(odata);
odata.connect().then(() => createApp(App).mount("#app"), showStartError);

In development, proxy /odata to the SAP CAP server ("/odata": "http://localhost:4004" in Vite's server.proxy). In production, serve the app where the service is reachable under the same origin, for example behind the same approuter or reverse proxy.

Moost server. Serve each entity set through a Moost controller that extends ODataTableController or ODataReadableController (see Moost Server), at the URLs you want the screens to keep:

ts
@TableController(catalog.Books, "api/catalog/Books")
export class BooksController extends ODataTableController<typeof catalog.Books> {}

Then build the screens with Atscript UI: a table is <AsTableRoot url="/api/catalog/Books">, and a form is built from the entity set's /meta, exactly as in the Quick Start.

Choose URLs you will keep

With a Moost server, the browser only knows /api/catalog/Books. In step 2 the controller behind that URL changes from an OData one to an Atscript DB one, and the screens do not change at all. With the browser client, step 2 changes the URL each screen is given from /odata/catalog/Books to the new endpoint.

Credentials ​

  • Browser client: the browser's own session is the login, as with a Fiori app on the same approuter or reverse proxy.
  • Moost server: it signs in its own users, and calls the service as a technical user (basicAuth, bearerAuth); the space keeps the session a write needs. See Credentials and Sessions.

When this step is done ​

The new screens run against the SAP CAP service, side by side with what you had. Nothing on the server has changed, and you can stop here. When you are ready to move the data and the logic, continue with 2. Move the Services.

SAP, SAP S/4HANA, SAP Fiori, SAPUI5, SAP BTP and other SAP products and services mentioned herein, as well as their respective logos, are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Atscript OData is an independent open-source project and is not affiliated with, sponsored or endorsed by SAP SE.
Released under the MIT License.