cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Contains function not working on multiple columns for search

David21
Explorer
0 Likes
355

Hello everyone,

I am using Cap Node.js (odata v4) which is connected to an external API(odata v2) through a destination. I'm implementing search functionality in Valuehelp dialog box and for that I need to query the external database because by default when you type some value in the search bar it only searches for that value in the Primary key column. I was using contains function to build the query and it works if it has only one column i.e. 

let query = cds.parse.cql(`SELECT * from DUMMY WHERE contains(firstName, '${req.query.SELECT.search[0].val}')`);

await externalService.tx(req).run(query);

But when I try to search in multiple columns using the following statement it gives an error:

let query = cds.parse.cql(`SELECT * from DUMMY WHERE contains((firstName,lastName)), '${req.query.SELECT.search[0].val}')`);

I have also tried using multiple contains and that works fine with the 'and' operator i.e. It gives me names that are common in both columns

let query = cds.parse.cql(`SELECT * from DUMMY WHERE contains(firstName, '${req.query.SELECT.search[0].val}') and contains(lastName, '${req.query.SELECT.search[0].val}'`);

But when I try to use use the query with 'or' operator it doesn't work and just returns all the values. Any suggestions on how to search in multiple columns ?

Accepted Solutions (0)

Answers (0)