cancel
Showing results for 
Search instead for 
Did you mean: 

Apply filters to nested fields in CAP

nitesh_bisht
Advisor
Advisor
0 Kudos
470

Hello,

We are trying to fetch business partners with filter of city through S4 API in CAP project.
As City is present inside Address composite entity, we are not able to apply filter on city.

// Not compiling as .eq doesnt come on BusinessPartner.TO_BUSINESS_PARTNER_ADDRESS.Country
bpList = businessPartnerService.getAllBusinessPartner().filter(BusinessPartner.TO_BUSINESS_PARTNER_ADDRESS.Country.eq("India"))

Can you please help us to know how a filter on composite/associated entity can be applied.

P.S :
We found following link which shows it can work, but this is only for javascript.

https://sap.github.io/cloud-sdk/docs/js/features/odata/use-odata-v4-type-safe-client-for-javascript-...

/*
  Get all business partners that match all the following conditions:
    - Have customer with the customer name 'name'
    - Have customer with the customer full name 'fullName'
*/
.filter(
  BusinessPartner.TO_CUSTOMER.filter(
    Customer.CUSTOMER_NAME.equals('name'),
    Customer.CUSTOMER_FULL_NAME.equals('fullName')
  )
)

We want to know if something similar is present in java.

Accepted Solutions (0)

Answers (1)

Answers (1)

gregorw
Active Contributor
0 Kudos

I would suggest you try the filter as a pure OData query against the backend service. You will learn that the S/4HANA Business Partner service does not support filtering on 1:n relationships. If you need to restrict to the country you should start by filtering the Address Entity and expand to the business partners. Also the Country must be an ISO Code.

nitesh_bisht
Advisor
Advisor
0 Kudos

Hi Gregor,

Thanks a lot for your prompt reply.

Can you please elaborate which function you mean by OData query. A short snippet will be very helpful for us to understand it.