cancel
Showing results for 
Search instead for 
Did you mean: 

Insert field into database type Decimal

fjcvsap
Participant
0 Kudos

Hi,

I try to insert into my database a value of field type Decimal(13, 2) and It's not working. My dataAmount value is: "14.54". I also tried with parseFloat(dataAmount) but still is not works.

const BigNumber = require('bignumber.js'); 
const sdkData = sdkTest.builder()
                    .id(dataId)
                    .amount(BigNumber(dataAmount))
                    .build();
 await sdkTest.requestBuilder().create(sdkData)
                   .setCustomServicePath('api/')
                    .execute({ destinationName: 'Test', jwt: jwt })
                    .catch(err => {
                        console.log('Error One:', err.message);
                        console.log('Cause:', err.rootCause.message);
                        console.log('Root cause:', err.rootCause.message);
                    });

Any help!

Best

Junjie
Advisor
Advisor
0 Kudos

Hi mrjer,

could you please share more information about the `sdkTest`. Please correct me. I assume this is a OData client you generated by using the SAP Cloud SDK OData generator. Also, it seems you are developing your app with CAP, so I assume for the field "amount" with data type Decimal(13, 2), the edm type is "Edm.Decimal".

Based on the assumption, when building the entity, the BigNumber is used correctly. Can you try

.amount(new BigNumber(dataAmount))

If it does not work, maybe you can share what's the error message?

fjcvsap
Participant
0 Kudos

Hi Junjie,

You right, the Odata Cliet was generated by using Sap Cloud SDK Odata generator and I am developing a Cap services with the field "amount" type Decimal(13,2) and the edm type is Edm.Decimal.

PD. sdkTest is a Java services and I want to insert from a Node Js service and between there is an api management.

I check the log of the services and I got this error:

Exception marked the ChangeSet 1646 as cancelled: Could not deserialize request payload: Invalid value for property 'amount'.

I aslo try it with amount(new BigNumber(dataAmount),amount(new BigNumber("11.11").

And only I can insert into table if I comment the amount.

const sdkData = sdkTest.builder().id(dataId)
                       //.amount(BigNumber(dataAmount)).build();

So I don't know what's wrong.

Junjie
Advisor
Advisor
0 Kudos

Hi M jerte,

The error message you shared did not seem to be thrown from the sdk. Could you please share more information on this?

Exception marked the ChangeSet 1646 as cancelled: Could not deserialize request payload: Invalid value for property 'amount'.

Also, I see your code:

                    .catch(err => {
                        console.log('Error One:', err.message);
                        console.log('Cause:', err.rootCause.message);
                        console.log('Root cause:', err.rootCause.message);
                    });

it would be great if you can share the whole stack trace about these.

Accepted Solutions (1)

Accepted Solutions (1)

fjcvsap
Participant

Hi,

I have already solved it just adding withCustomHeaders({ 'Content-type': 'application/json;charset=UTF-8;IEEE754Compatible=true' })

await sdkTest.requestBuilder().create(sdkData)
                   .setCustomServicePath('api/')
                    .withCustomHeaders({ 'Content-type': 'application/json;charset=UTF-8;IEEE754Compatible=true' })
                    .execute({ destinationName: 'Test', jwt: jwt })
                    .catch(err => {
                        console.log('Error One:', err.message);
                        console.log('Cause:', err.rootCause.message);
                        console.log('Root cause:', err.rootCause.message);
                    });

Thank you very much for your help.

Answers (0)