Search code examples
javas4sdk

Application programming model $filter operation


After implementing all steps in Deep dive 12, I've been trying to use $filter operation like a normal oData service should do.

Deep Dive 12

https://baseurl/odata/v2/CrudService/BusinessPartner?$filter=BusinessPartnerCategory eq 'abc'.

However, it doesn't work. It always returns the same entity set. I've looked at its javadoc. There seems no methods for retrieving filters. I see there are getTopOptionValue, getSkipOptionValue, getSelectProperties and getOrderByProperties.

What are options to get values of $fitler operation?

Another thing is in deep dive 4. I see that the filter is hardcoded.

Deep dive 4

final List<BusinessPartner> businessPartners =
                    new DefaultBusinessPartnerService()
                            .getAllBusinessPartner()
                            .select(BusinessPartner.BUSINESS_PARTNER,
                                    BusinessPartner.LAST_NAME,
                                    BusinessPartner.FIRST_NAME,
                                    BusinessPartner.IS_MALE,
                                    BusinessPartner.IS_FEMALE,
                                    BusinessPartner.CREATION_DATE)
                            .filter(BusinessPartner.BUSINESS_PARTNER_CATEGORY.eq(CATEGORY_PERSON))
                            .orderBy(BusinessPartner.LAST_NAME, Order.ASC)
                            .execute();

What do I need to build a dynamic filter statement that may contain multiple filters?

Thanks


Solution

  • I also include the answer originally posted on the blogpost here. Just in case someone takes a look at Stackoverflow only.

    Currently filtering is not available in the SAP Cloud Platform SDK but on the roadmap.

    Here is a workaround using custom Query options to call the S/4HANA Cloud SDK in a custom handler. Make a request like …. BusinessPartner?$top=10&$skip=1&BusinessPartner eq 1&BusinessPartnerCategory < 1

    However this is very “hacky” and I cannot recommend this approach.

    Best Regards,

    Daniel