on 02-11-2020 7:03 AM
Hello SAP Cloud SDK Experts,
I'm working through the Tutorial Mission Use CAP and SAP Cloud SDK to Extend S/4HANA. But instead of using the S/4HANA based Business Partner I've created a simple OData Service based on the EPM Business Partner in my AS ABAP. To make it easer to replicate my issue I've created a mock service for this OData service. As the next step I've followed Generate Custom OData Client Library with SAP Cloud SDK's Generator. To get a typed interface for my consumer app.
So far so good. The result of the generation is i.e. the EpmBusinessPartnerSet.ts file with all the attributes of the entity-set. But not like in the EDMX tile ZEPM_BP_SRV.edmx that was used as the source the attributes i.e. BpId do start always with a lowercase letter i.e. bpId. So as a result I needed to adjust the case of the fields in my service definition so that the service implementation works with the generic select.
Is there a way to change this behaviour of the generator? Or is there even an easier way to consume the OData service?
Best regards
Gregor
Hi Gregor,
thank you for reaching out to us! If I understand you correctly, you're exposing an OData service using CAP and want to provide some of that data from a downstream service, that you consume using code generated by the SAP Cloud SDK's OData client generator.
Lowercasing the properties in the resulting JavaScript code was a conscious decision in order to stay in line with how you'd typically define properties in JavaScript. That being said, the SDK's core package (@sap/cloud-sdk-core) exports a function "serializeEntity" that converts the result of a service call to OData JSON format (so just the normal format that is used to communicate with the service anyway). If you apply this function before calling select, this should allow you to get around the formatting issue. So in your case this would be:
const { FilterList, serializeEntity } = require('@sap/cloud-sdk-core');
const epmbps =
await EpmBusinessPartnerSet.requestBuilder()
.getAll()
.filter(createFilter(results))<br> .execute(destination)
.then(businessPartners => businessPartners.map(bp => serializeEntity(bp, EdmBusinessPartnerSet)))
While this is a workaround for now, please let us know whether this solves your problem!
If you have ideas on how to approach this problem in general, we'd also be interested in hearing your perspective!
Best regards,
Dennis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Dennis,
I've included your suggestion in this last commit. Works like a charm.
I still have the feeling that the case of the used service should be respected and don't care about the normal JavaScript conventions.
Best regards
Gregor
Glad to hear it worked! We will take a look whether this is something that our current design allows implementing easily or whether this would require a larger rework.
Hi Dennis and Gregor,
I was using the solution provided in this comment and was working properly, but today I executed my process again and it didn't work.
Here, "il" has the correct data but after the serializeEntity I received {}:
.then(result => result.map(il => serializeEntity(il, InspectionLot)))
I had not run it for a long time, I don't know when it stopped working.
Do you know if there has been any change in this?
Thanks in advance,
Marc
Hi marc.mauri,
I faced the same issue in my sample project epmbp-consumer-app. I was able to fix it by switching from @sap/cloud-sdk-core to @sap-cloud-sdk/core.
Best regards
Gregor
User | Count |
---|---|
77 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.