Skip to Content
0
Jun 01, 2022 at 08:36 AM

SAP BAS CAPM debugging via request.https

289 Views Last edit Jun 01, 2022 at 09:28 AM 2 rev

Hi ,

In my CAPM Project leveraging sqlite db ,i have implemented UPDATE statement but somehow below (Myservice.js) one is not working. Hence i try to debug this in SAP BAS using request.https script file - I clicked on Send Request(in script file) its showing error "Header name must be a valid HTTP token ["post https"]".

So can you please help me on this.

request.https:

Send Request

POST https://port4004-workspaces-ws-6hqg8.us10.trial.applicationstudio.cloud.sap/srv/CatalogService/Category

Content-Type: application/json

{ "ID":3, "PRODUCTID": 3, "PRODUCTNAME": "Aniseed Syrup", "QUANTITYPERUNIT": "12 - 550 ml bottles", "UNITPRICE": 10, "UNITSINSTOCK": 15, "UNITS":15 }

Myservice.js:

module.exports = (srv) => {
const {Product} = cds.entities ('my.product') srv.before ('UPDATE', 'Category', async (req) => { const category = req.data if (!category.UNITS || category.UNITS <= 0) return req.error (400, 'Units in stock should be greater than zero') const tx = cds.transaction(req) const affectedRows = await tx.run ( UPDATE (Product) .set ({ UNITSINSTOCK : {'=': category.UNITS }}) .where ({ PRODUCTID: {'=': category.PRODUCTID}}) ) if (affectedRows === 0) req.error (409, "No Product available, sorry") })
}

Myservice.cds:using {my.product as my } from '../db/product';@path: 'srv/CatalogService'service MyService { entity Product as projection on my.Product; entity Category @updateonly as projection on my.Category;}