These are the minimum steps for creating our own custom services application based on a CAP app from scratch.
📺Video Tutorial: You can either follow the steps below or watch the video (10 minutes) where I show each and every step needed in full detail.
-> Video Tutorial - Custom Services
The above video shows very nice all the detailed steps including both the CAP and also the Sales and Service V2 custom services part.
If you want to see less CAP Development and more on how it looks later for the end-user I can recommend you to watch this more high level overview video.
PS: If you are also interessted in some very basics about extensibility you can also check out my main page with a guide on mashups and custom code in a cloud function.
Pre-requisites:
- You have a BTP sub-account and access to Cloud Foundry (you can use a free BTP Trial)
- You have setup a Hana Cloud on your BTP Sub-Account (take a look here for the basic steps needed)
- You have setup VSCode and done the initial setup for CAP
- You have enabled the Custom Services feature for creating new entities in your SAP Sales and Service Cloud V2
- You are a little bit familiar with coding or curious enough to get into it :)
Step by Step Guide:
- Open VSCode and the terminal
- Enter in the terminal
cds init ProjectOrder - Enter in the terminal
code ProjectOrder(on windows at least this opens the project in visual code :P) - Create
schema.cdsfile with your entity in the db folder -> Snippet 1
Snippet 1:
using {managed} from '@sap/cds/common';
namespace sap.capire.customservice;
entity ProjectOrder : managed {
key id : UUID;
name : String not null;
customerName : String;
status : String default 'ACTIVE';
startDate : String;
endDate : String;
isIndividualCustomer : Boolean;
customerEmail : String;
}
- Create
project-order-service.cdsfile in the srv folder with your service definition -> Snippet 2
Snippet 2:
using {sap.capire.customservice as projectorderschema} from '../db/schema';
service ProjectOrderService @(path: '/project-order-service') {
@odata.draft.bypass
entity ProjectOrder as projection on projectorderschema.ProjectOrder;
}
- Enter in the terminal
cds add hana
cds add xsuaa
cds add mta
cds add approuter
- Adapt some files manually…
-> Adjust the package.json (overwrite the cds section by changing auth to mocked and adding the hana db) -> Snippet 3
Snippet 3:
"cds": {
"requires": {
"[production]": {
"db": "hana",
"auth": "mocked"
},
"auth": "mocked"
}
}
-> Adjust the app/router/xs-app.json by adding CORS exceptions (for your tenant) and adjust authMethod=none -> Snippet 4 and 5
Snippet 4:
"authenticationMethod": "none",
Snippet 5:
,
"cors": [
{
"uriPattern": "(.*)",
"allowedMethods": [
"GET",
"POST",
"OPTIONS",
"PATCH",
"PUT",
"DELETE"
],
"allowedOrigin": [
{
"host": "localhost",
"protocol": "http",
"port": 5000
},
{
"host": "localhost",
"protocol": "http",
"port": 4100
},
{
"host": "localhost",
"protocol": "http",
"port": 4200
},
{
"host": "ns-staging.cxm-salescloud.com",
"protocol": "https"
},
{
"host": "YOURTENANT.de1.demo.crm.cloud.sap",
"protocol": "https"
}
],
"allowedHeaders": [
"Accept",
"Authorization",
"Content-Type",
"Access-Control-Allow-Credentials",
"sap-c4c-rawagent",
"X-Csrf-Token",
"If-Match"
],
"exposeHeaders": [
"Etag",
"X-Csrf-Token"
],
"allowedCredentials": true
}
]
-> Adapt the mta.yaml by changing the generated hana db name according to your own DB name (3 places in i.e. to “name: customservice-basic-db”)
-> In case your BTP subaccount has spaces in it’s name: adjust the xsappname: ProjectOrder in your mta.yaml by removing the generated placeholders for subaccount and space.
-> Optional hint: Add 128M memory to all your services in mta.yaml to save some dev space
- Enter in your terminal
npm update --package-lock-only
mbt build
cf login
cf deploy mta_file
-
Copy the app router url and try out your backend service.
-
Enter in the terminal
cds -2 json .\srv\projectorder-service.cdsand copy the json into a new file. -
Create a new custom service entity in the Sales and Service Cloud V2 frontend, convert the CAP json file, download the final json definition and upload it in custom services
-
Add UI’s to your custom service
-
Assign it to your user via a business role
-
Test!


