Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
lukcad
Explorer

Goals:

1-- create one Full-Stack application for management products based on Northwind service http://services.odata.org

2-- enhance application to meet the business requirements.

Business requirements:

1-- Main list of products should have at least 3 columns: `Product Name`, `Category` and `Supplier`

2-- Should be added filleters by `Category` and by `Supplier` for main list.

3-- Each record can be editable on `Details` page which also has additional list of items from orders where product was requested to understand impact.

Prerequisites:

As a developer to go through steps of this article:

  • you have an account in SAP BTP.
  • you know SAP BTP and know how to create dev Full-Stack environment.
  • you have GitHub where you can save your project
  • you added application SAP Build Code to your subaccount
  • you know how to develop CAP and UI by Fiori elements
  • you understand CDS and know about any consequences if model in CDS should be changed.
  • you have heard about `Joule`.

Creating project for products

In this document, you will create project according to our goals and the business requirements, steps will be like these:

  • Prepare project
    • creating project
    • initial commit project to GitHub
  • Generate components of project
    • generate data model by Joule
    • commit project to GitHub
    • generate sample data by Joule
    • commit project to GitHub
    • generate FIORI UI
    • commit project to GitHub
  • Implement business requirements
    • change your FIORI pages according requirements
    • commit project to GitHub
    • manual testing
    • final commit to GitHub

Prepare project

Go to SAP BTP and open tool `SAP Build Code` which you previously adjusted by Booster or by documentation.

Go to `Lobby` of your applications and create new application with name `zproducts` (you can use your name).

Use this road map to create project:

Create -> Build Application -> SAP Build Code -> Full-Stack Application

lukcad_0-1712691988211.png

Once project is prepared in your Lobby, open it by hitting Name from list of projects:

lukcad_1-1712691988213.png

You will have opened SAP build tool with generated application which you will develop:

lukcad_2-1712691988215.png

Before go with `Joule` I recommend use GitHub to save your versions (if something wrongly generated and you did accept it you will be able to restore everything to save time):

we add our project to GitHub by creating repository, in this example it is `zproducts`

lukcad_3-1712691988216.png

and you save initial commit to  GitHub:

 

 

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/lukcad/zproducts.git
git push --set-upstream origin main

 

 

Preparation is done.

Generate components of project

Create model

Use this road map:

Go to Joule ->Open Guide->Data Model and Service Creation

Tell to Joule:

create model from Northwind service which is placed on http://services.odata.org

lukcad_5-1712691988219.png

Accept changes. You will find model is added.

lukcad_6-1712691988221.png

open terminal and run `cds w`

lukcad_7-1712691988224.png

Open proposed link, usually it is http://localhost:4004

lukcad_8-1712691988226.png

Model is prepared by Joule and verified by you.

Save it on GitHub by new commit for a  reason:

lukcad_9-1712691988227.png

Generate Sample Data

Use this road map:

Joule->Open Guide->Sample Data->Generate Sample Data

Tell to Joule:

Generate sample data for model.

lukcad_10-1712691988229.png

After pressing on `Accept data` editor of sample data is opened and you can check data for all tables:

lukcad_11-1712691988232.png

Start again cds server if it is stopped.

check our services by  http://localhost:4004

lukcad_12-1712691988234.png

You should have data for each service, as example for Products:

lukcad_13-1712691988235.png

Save this steps on GitHub by new commit for a reason.

lukcad_14-1712691988236.png

Generating UI

On this step you generate UI.

Use this road map:

Open Palette->FIORI: Generate Fiori Application

lukcad_15-1712691988238.png

choose template  Working Page -> Use local CAP project

lukcad_16-1712691988239.png

Press next

Choose main entity Products

lukcad_17-1712691988239.png

Press next

Give these parameters:

Module name

products

Application title

Products

Description

Products management

Allow FLP configuration

Yes

lukcad_18-1712691988240.png

Press next

Give these parameters for FLP:

Semantic Object

zmlproducts

Action

Management

Title

Products Management

lukcad_19-1712691988241.png

Press Finish

Finally you should be able for app/products by opening context menu choose `Show Page Map`

lukcad_20-1712691988242.png

Verify application, by start prepared run configuration or start cds server via terminal.

lukcad_21-1712691988243.png

This Home will be opened for our application:

lukcad_22-1712691988245.png

 

Open our Fiori application `Products`

lukcad_23-1712691988247.png

Open details for product:

lukcad_24-1712691988247.png

Try edit it:

lukcad_25-1712691988248.png

Try save it:

lukcad_26-1712691988249.png

Generating UI based on FIORI template is done. Commit this step to GitHub:

lukcad_27-1712691988250.png

Implement business requirements

We have to implement three business requirements:

1-- Main list of products should have at least 3 columns: `Product Name`, `Category` and `Supplier`

2-- Should be added filleters by `Category` and by `Supplier` for main list.

3-- Each record can be editable on `Details` page which also has additional list of items from orders where product was requested to understand impact.

Let's start.

Open Page Map by opening context menu for app/products and choosing `Show Page Map`

lukcad_28-1712691988251.png

In `Map Page` press on edit button of List Report and set this parameter:

Allows you to hide the filter bar:

False

lukcad_29-1712691988252.png

Now we have to change what we should see about Category and Supplier into our list. In ProductList view we go to Table -> Columns and change `Text` property to category/CategoryName

lukcad_30-1712691988253.png

Continue changing with field `Supplier`.

We change value of Text parameter to `supplier/CompanyName'

Let's move columns Category and Supplier to position after Product Name:

lukcad_31-1712691988253.png

Return to `Page Map` and go to ProductObjectPage in Edit mode.

Choose Sections -> General Information and change Labe to Details

lukcad_32-1712691988254.png

Convert Details name to i18n record.

lukcad_33-1712691988254.png

Add group section `Product` and save Label name into i18n

lukcad_34-1712691988255.png

Enhance association in model

Go to CDS model into db/schema.cds and add ability to expand data from Products entity to OrderDetails by adding so named `managed back association` (because association between OrderDetails to Products exists, so it doesn't change our model).

Find entity Products and add this element:

 

 

 

orderdetails: Association to many OrderDetails on orderdetails.product = $self;

 

 

 

Your fragment of code in `schema.cds` for entity Products should be as following:

 

 

 

entity Products {
  key ID: UUID;
  ProductID: Integer @assert.unique @mandatory;
  ProductName: String(40);
  QuantityPerUnit: String(20);
  UnitPrice: Decimal(10,4);
  UnitsInStock: Integer;
  Discontinued: Boolean;
  category: Association to Categories;
  supplier: Association to Suppliers;
  orderdetails: Association to many OrderDetails on orderdetails.product = $self;
}

 

 

lukcad_37-1712691988257.png

run `cds w` to verify that your services are working after change.

Continue with applying business requirements in Fiori

Once association is declared we can go and add `ordersitems` table to Details page.

Go back to Page Editor, and open Sections ->  and press + to choose `Add Table Section` with parameters:

Label

Items of Orders

Value Source

orderdetails

lukcad_38-1712691988258.png

For table of our section add Basic columns

lukcad_39-1712691988258.png

We add these fields to columns

order_ID,product_ID,Quantity,UnitPrice

and mark `Read Only`

lukcad_40-1712691988258.png

Run Application and test

1-- Check that there are columns: `Product Name`, `Category` and `Supplier` in the main list of Products

lukcad_41-1712691988259.png

2-- Check that there are accessible filleters by `Category` and by `Supplier`:

lukcad_42-1712691988260.png

lukcad_43-1712691988260.png

lukcad_44-1712691988261.png

3-- Check that there is `Details` editable view with list which shows `Items of Orders` to understand where Product has been used:

lukcad_45-1712691988263.png

Manually add new record for any product by using Sample data editor for test data file `Northwind_OrderDetails.csv`

lukcad_46-1712691988263.png

Check that Details able to show you two records for `Items of Orders`:

lukcad_47-1712691988264.png

Save to GitHub last commit if any changes have been done. Later on, you can enhance, build and deploy this project by using MTA in any moment.

Thank you for your time,

Yours sincerely,

Mikhail.

PS: You can find source code of this explained example on GitHub: 

https://github.com/lukcad/zproducts.git

 

 

 

 

Labels in this area