Skip to Content

Insert field into database type Decimal

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

Add a comment
10|10000 characters needed characters exceeded

  • 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.

  • 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.

  • Hi M jerte,

    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?

Related questions

1 Answer

  • Best Answer
    Posted on Feb 23 at 01:18 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.