cds init bookshop --add multitenancy,samples,mta,approuter
CAP docs about adding multitenancy: https://cap.cloud.sap/docs/guides/multitenancy/#enable-multitenancy
CAP docs about deploying: https://cap.cloud.sap/docs/guides/deployment/as-saas
cds init bookshop --add multitenancy,samples,mta,approuter
CAP docs about adding multitenancy: https://cap.cloud.sap/docs/guides/multitenancy/#enable-multitenancy
CAP docs about deploying: https://cap.cloud.sap/docs/guides/deployment/as-saas
With this simple command, you can download the MTA deployment logs of your recent deployment. Instead of manually having to use cf dmol -i <operation id>
, just save the command (replace appId with your Id) as a shell script, make it executable (chmod +x) and run the script after your deployment. It stores the recent logs into the folder logs.
dmol
is short for download-mta-op-logs
cf download-mta-op-logs --mta <appId> --last 1 -d logs
To just have a quick look at the recent logs, use
cf logs <appId>-srv --recent
To check if a record exists, you can simply use the HEAD query.
“HEAD is almost identical to GET, but without the response body.” (https://www.w3schools.com/tags/ref_httpmethods.asp)
Unfortunately, there is no shortcut in CAP for a HEAD
query, so simply use send
with method HEAD
.
sfsfSrv = await cds.connect.to('sfsf')
try {
await sfsfSrv.send('HEAD', `/User('${userId}')`)
return true // status 200
} catch (err) {
return false // status 404
}
https://cap.cloud.sap/docs/cds/common#aspect-cuid
const result = await INSERT(payload).into(table)
const newEntries = [...result]
console.log("New ID: " + newEntries[0].ID)
const cds = require('@sap/cds');
module.exports = async srv => {
const { Objects } = srv.entities // entities from myService.cds
srv.on("myAction", async req => {
const query = SELECT.one.from(Objects).where({ id: req.data.myId })
const srv = await cds.connect.to('myService')
const data = await srv.run(query)
console.log(data)
return data
})
srv.on("READ", Objects, async req => {
console.log("Objects called")
// Select data from db or forward query to external system
// ...
// return data
})
}
# check if ssh is enabled
cf ssh-enabled myapp
# if it's not, enable it and restart app
cf enable-ssh myapp
cf restart myapp
# access with
cf ssh myapp
Create your script file, make it executeable and add it to your .gitignore as it contains sensitive information:
touch login.sh
chmod +x login.sh
echo login.sh >> .gitignore
Open the file and paste the following:
#! /bin/bash
cf login <<!
myemail@mail.com
password
1
!
With “1” you select your target space. Save your script and run it using:
./login.sh
After some time, it can happen that the default identity provider of the SAP BTP (SAP ID service) is asking for a password change. I don’t know exactly, but it seems to be every 90 days?!
The login process will fail with the following output:
$ ./scripts/login.sh
API endpoint: https://api.cf.eu10.hana.ondemand.com
Email: myemail@mail.com
Password:
Authenticating...
{"error":"invalid_grant","error_description":"User authentication failed: PASSWORD_CHANGE_REQUIRED"}
To change your password, just go to https://accounts.sap.com/, and it should directly open the password change screen.
Since CDS 5.9.2 this is the quickest way of creating and deploying the bookshop sample:
cds init bookshop
cd bookshop
cds add samples
cds add hana
cds add xsuaa
cds add mta
npm install
mbt build
cf deploy mta_archives/bookshop_1.0.0.mtar
https://sap.github.io/cloud-sdk/docs/js/features/connectivity/destination
const { getDestination } = require("@sap-cloud-sdk/core")
const myDestination= await getDestination("myDestination")
if (myDestination === null) throw Error(`Destination "myDestination" not found`)
for (let key in myDestination) {
console.log(key, myDestination[key])
}
If the default port 4004 is already open and you want to see what is bound to it, select View -> Find Command -> Ports Preview
Solution to kill another “watch.js” process using/blocking the port: https://answers.sap.com/questions/13016130/sap-business-application-studio-stop-running-serve.html
To archive the same in a single command use:
lwctl -c basic-tools kill -9 $(lwctl -c basic-tools ps aux | grep watch.js | awk '{print $2}')
As alternative, change the default port by adding a new port in package.json to the start script, for example: “start”: “cds run –port 4003” and use npm run start instead of cds watch.