on ‎2020 Apr 02 5:30 PM
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.
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
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 }).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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! 😉
Hello Marika,
Thank you for you answer. Should I open a feature request in GitHub?
It would be nice to have a workaround for this in the time being, it would be the final piece to an application I am working on 🙂
In the meanwhile, I am trying to execute the request directly using axios, I'll let you know if it works.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear marika.marszalkowski
I did a quick and dirty test. Something seems to work, but then I got stuck.
I first get the full URL from the request builder:
const odataRequest: ODataRequest<ODataGetAllRequestConfig<EmpPayCompRecurring>> =
await 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))
.build({ destinationName: this.configService.get<string>('ACTIVE_DESTINATION')});
From the request, the URL and Headers can easily be taken by:
const fullUrl = `${odataRequest.url()}&fromDate=1970-01-01&toDate=9999-12-31`;
const headers = await odataRequest.headers();
And the Axios request:
const odataResult: axios.AxiosResponse<any> = await axios.default.get(fullUrl, {
method: odataRequest.config.method,
headers: headers
});
I am able to get results, the response is there.
But now I got stuck in deserializing the entity...I tried using:
deserializeEntity(d, EmpJob.requestBuilder()._entityConstructor);
But it fails with:
Error Cannot read property '_allFields' of undefined
I believe I did something wrong 🙂
Hope you can point me in any direction!
Thanks,
Roberto.
Hello Roberto,
that sounds like a sensible feature. We just planned to work on that, so probably we will release this feature soon. Is this time critical for you and do you still need a workaround for that in the mean time?
Regards,
Marika
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.