Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[CAP] Parses a string in CQL expression and add it as WHERE condition

https://cap.cloud.sap/docs/node.js/cds-compile#cds-parse-xpr

Some examples:

// equal
cds.parse.xpr (`lastName = 'Naidoo'`)

// or
cds.parse.xpr (`lastName = 'Naidoo' or firstName = 'Verónica'`)

// in
cds.parse.xpr (`lastName IN ('Naidoo','González Esteban')`) 

How to add an expression as where condition:

    srv.before('READ', EntityName, async req => { 

        const cxn  = cds.parse.xpr (`lastName = 'Naidoo'`) 

        req.query.SELECT.where ??= []
        if (req.query.SELECT.where.length > 0) {
            req.query.SELECT.where.push("and")
        }
        req.query.SELECT.where.push(...cxn)

    })

Leave a Reply

Your email address will not be published. Required fields are marked *