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

SAP Cloud SDK for JavaScript: Custom Query parameters

former_member231229
Participant
0 Likes
39,495

Hello all,
as usual, another question is raising while my journey through the SDK is going further.

I am using the SDK to consume SuccessFactors OData API, and it is working great. It is an incredibly powerful tool and amazing things can be done leveraging it.
However, I came across a very specific situation which is currently not supported (fairly, I have to say) by the SDK.

In SuccessFactors, we can query for effective-dated entities but the standard behavior is to return only actual records (= records valid as of today) unless two custom query parameters are present in the URL:

.../EmpJob?$select=startDate,companyNav/externalCode&$format=json&fromDate=2000-01-01&toDate=9999-12-31

The two parameters fromDate and toDate are instructing the API to actually fetch all records that are falling in the specified interval.

From the SDK fluent API, we can construct the full URL of the built query by:

EmpJob.requestBuilder().getAll().select(...).filter(...).build({}).url()

So that custom query parameters can be easily added to it by concatenation.

Question is: how can I then shoot the request with the newly defined URL? Or better...is there a way to inject custom query parameters while building the request?

Thanks a lot in advance,

Roberto.

View Entire Topic
0 Likes

Hello Roberto,

I was actually already working on this today, you can find the according pull request here: https://github.com/SAP/cloud-sdk/pull/74.

We should be able to merge this tomorrow. For your workaround, I am not sure what might be the issue, maybe you can try

deserializeEntity(d, EmpJob);

If this doesn't work it might be interesting to know what the data looks like?

UPDATE:

This feature is available with version 1.19.0, use:

EmpJob.requestBuilder().withCustomQueryParameters({ param: value }).
former_member231229
Participant
0 Likes

Hello Marika,
Yes, it works! Thank you!

I will live with this waiting for the merge.

Thank you so much!

Roberto

former_member231229
Participant
0 Likes

After upgrading to 1.19.0 everything works perfectly.

For SuccessFactors API consumers, here is how you can fetch also historical records from the system (this is an example using entity EmpPayCompRecurring):

EmpPayCompRecurring.requestBuilder().getAll().select(
      EmpPayCompRecurring.PAY_COMPONENT,
      EmpPayCompRecurring.PAYCOMPVALUE,
      EmpPayCompRecurring.START_DATE,
      EmpPayCompRecurring.FREQUENCY_NAV.select(
        FoFrequency.ANNUALIZATION_FACTOR
      )
    ).filter(EmpPayCompRecurring.USER_ID.equals(userId)).withCustomQueryParameters({ fromDate: '1970-01-01', toDate: '9999-12-31'})
    .execute({ destinationName: this.configService.get<string>('ACTIVE_DESTINATION')});

Hands up for the SDK team! 😉