cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass filters at runtime to Cloud-SDK in CAP application

0 Kudos

Hi Everyone,

I am trying to build an side by side extension scenario using CAP. In the project, I've generated typed client for on-premise odata service. I am able to get data for plain simple entityset by using following code.

However, when I want to pass dynamic filters, I am unable to do so. The documentation only talks about passing static filters here, however I need to pass dynamic filters (based on what request is being called) instead of hard-coding static values. Please advise if you have encountered such situation.

View Entire Topic
mvaibhav
Contributor

Hi adwaitcf251 ,

You may have to read the filters from the request, form the filter structure as mentioned below and use it in the getAllCarriers() method to get the filtered data.
The filter values passed dynamically will be available in the req parameter of the on Read Method of the entity.

const { or, and } = require('@sap-cloud-sdk/odata-v2');

ztestscarrSetApi.requestBuilder().getAll()
.filter(
	or(
	  and(
	    ztestscarrSetApi.schema.CARRID.equals(value of carrid read from request filter),
	    ztestscarrSetApi.schema.CURRCODE.equals(value of currcode read from request filter),
	     ),
	  ztestscarrSetApi.schema.CARRNAME.equals(value of carrname read from request filter) )
).execute(destination);

Thanks,

Vaibhav Maheshwari