on 06-01-2022 9:36 AM
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
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;}
I tried to reproduce your problem. It seems like you explicitly have the "Send Request" as string in your file. You need to take that out. The tooling (rest client) will show "Send Request" hovering above your HTTP request. Once you click on that you get the proper behavior. I tried your URL, but received a 404
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Martin now i able to Send Request.
Facing one more issue , when i send the request - am getting response as attached , due to this i unable to debug. Can you please help to fix this one also.
HTTP/1.1 401 Unauthorised
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.