0

I know I am reopening an old one (Perform filter on expanded entity with SAP Cloud SDK), but it was a while ago and was referencing the Java version of the API used to consume an S/4 HANA service.

I'm testing the Javascript version of the API against the SuccessFactors OData API, which is indeed able to perform filters on expanded entities, like so:

<API_HOST>/odata/v2/PerPerson?$filter=personalInfoNav/firstName eq 'MARCO'&$expand=personalInfoNav&$select=personalInfoNav/firstName, personalInfoNav/lastName&$top=20

Translated into the SDK, it would be (TypeScript):

const personList: Array<PerPerson> = 
    await PerPerson.requestBuilder().getAll().top(20)
        .select(
            PerPerson.DATE_OF_BIRTH,
            PerPerson.PERSONAL_INFO_NAV.select(
                PerPersonal.PERSON_ID_EXTERNAL,
                PerPersonal.FIRST_NAME,
                PerPersonal.LAST_NAME,
                PerPersonal.GENDER
            )
        ).filter(PerPersonal.FIRST_NAME.equals('MARCO'))
         .execute({ destinationName: this.configService.get<string>('ACTIVE_DESTINATION') });

But this code does not compile because of the incompatibility of types for the filter function, which here expects a "PerPerson" type and not "PerPersonal". I was not able to find anything about this.

Considering that the plain OData query works perfectly, anyone has been able to make this work?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
  • 1
    Does this answer your question? [Perform filter on expanded entity with SAP Cloud SDK](https://stackoverflow.com/questions/56144905/perform-filter-on-expanded-entity-with-sap-cloud-sdk) – Suncatcher Feb 18 '20 at 08:59
  • OData V2 is subject to the same rules no matter which type of Cloud Connector is used, Java or JS. It's a limitation of Odata implementation. So the question is no, filter is not possible. – Suncatcher Feb 18 '20 at 09:01
  • I understand, but that's not the case. SDK or not, SuccessFactors OData V2 implementation applies filters on expanded entity and the URL i posted is an example of that. It really depends on the server side implementation, and SuccessFactors actually supports it. – Roberto Pagni Feb 18 '20 at 11:17

1 Answers1

0

Update:

I didn't initially understand that Successfactors offered this functionality on top of the protocol. There are two possible workarounds I can think of:

  1. use new Filter, e.g.:
PerPerson.requestBuilder().getAll().top(20)
  .select(
   ...
  ).filter(
    new Filter('personalInfoNav/firstName', 'eq', 'MARCO')
  )
...
  1. If this doesn't work, you can call build on the request builder instead of execute, which gives you the ODataRequest object from which you can get the URL, which you'd then have to manipulate manually. Then you should be able to use the executeHttpRequest function to execute this custom request object against a destination.

Let me know if one of these work for you!


Original answer:

filtering on expanded entities on OData v2 is only possible if the relationship between the two entities is 1:1. In the case the code would look like this:

PerPerson.requestBuilder().getAll().top(20)
  .select(
    PerPerson.DATE_OF_BIRTH,
    PerPerson.PERSONAL_INFO_NAV.select(
      PerPersonal.PERSON_ID_EXTERNAL,
      PerPersonal.FIRST_NAME,
      PerPersonal.LAST_NAME,
      PerPersonal.GENDER
    )
  ).filter(
    PerPerson.PERSONAL_INFO_NAV.filter(
      PerPersonal.FIRST_NAME.equals('MARCO')
  ))
...

If, however, the relationship is 1:n, filtering is not possible.

Hope that helps!

Dennis H
  • 589
  • 4
  • 10
  • Hello Dennis, and thank you. I know that in the OData model the relationship between PerPerson and PerPersonal is 1:N and from that came my question. I understand the generic nature of the SDK, but given the fact that SuccessFactors actually supports this kind of filtering, do you think is there a way to achieve it via any kind of workaround using the SDK? – Roberto Pagni Feb 18 '20 at 11:21
  • Looks like I didn't read your question careful enough, my bad. I'll provide an update in my answer. – Dennis H Feb 19 '20 at 09:17
  • Hello Dennis, first option works like a charm for me! Thank you so much! – Roberto Pagni Feb 25 '20 at 10:22