cancel
Showing results for 
Search instead for 
Did you mean: 

First letter of entity attributes converted to lowercase by @sap/cloud-sdk-generator

gregorw
Active Contributor
0 Kudos

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

gregorw
Active Contributor
0 Kudos

Please check out my follow up question on this topic Using destination from package.json / default-env.json in implementation

View Entire Topic
dhem
Active Participant

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

gregorw
Active Contributor
0 Kudos

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

dhem
Active Participant

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.

marcmaurí
Participant
0 Kudos

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

dhem
Active Participant
0 Kudos

Hi Marc,

from the top of my head, I'm not aware of any changes to `serializeEntity`. Something must have changed, of course. I assume you ran npm install and some dependencies got updated? Do you have an older state of the package-lock.json that you can diff the current one against?

marcmaurí
Participant
0 Kudos

Hi Dennis,

Thanks for your answer.

Yes, I did. It was working fine in late February, I guess I ran npm install a couple of times since then. I have some backups of this file, I will check it and let you know if I find something relevant.

Best regards,

Marc

gregorw
Active Contributor
0 Kudos

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

marcmaurí
Participant
0 Kudos

Hi gregorw,

thanks for your support once again, it works great.

Best regards,

Marc