Skip to Content

SAP Cloud SDK for JavaScript: unable to post entry with a date field

Hi,

I am trying to create a material document header using the following request payload which has postingdate as mandatory field.

MaterialDocumentHeader {
  goodsMovementCode: '01',
  postingDate: '2020-04-11T10:00:00',
  toMaterialDocumentItem: [
  // not relevant 
}

When I try to post, console says the following. Seems like issue with Datetime conversion.

TypeError: momentInstance.unix is not a function
    at Object.momentToEdmDateTime (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\payload-value-converter.js:82:36)
    at Object.tsToEdm (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\payload-value-converter.js:32:36)
    at C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\entity-serializer.js:47:75
    at Array.reduce (<anonymous>)
    at serializeEntityNonCustomFields (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\entity-serializer.js:40:32)
    at Object.serializeEntity (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\entity-serializer.js:26:34)
    at CreateRequestBuilder.prepare (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\request-builder\create-request-builder.js:84:58)
    at CreateRequestBuilder.<anonymous> (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\request-builder\create-request-builder.js:110:22)
    at step (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\request-builder\create-request-builder.js:47:23)
    at Object.next (C:\Users\xxx\my-sdk-project\node_modules\@sap-cloud-sdk\core\dist\request-builder\create-request-builder.js:28:53)

Anyone faced this issue before? Or am I doing anything wrong?

Regards,

Tejaswi

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on May 18 at 12:40 PM

    Hello Tejaswi,

    when I look at the typescript definition of the document header it looks like:

    postingDate?: Moment;

    So the posting date should be a moment instance. Could you try to create a instance like described here: https://momentjs.com/docs/

    Let me know if this helps.

    Best

    Frank

    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.