cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

Hi,

I am developing a solution using CAPM.

I am using the S/4 HANA Cloud API API_JOURNALENTRYITEMBASIC_SRV as an external service.

My problem is when I try to consume an EntitySet that returns an attribute of tipe Edm.Date (for example A_CostCenter entityset).

The error is "Invalid value /Date(253402214400000)/ (JavaScript string). A string value in the format YYYY-MM-DD must be specified as value for type Edm.Date."

I think the CAPM framework is expecting a format YYYY-MM-DD, but S/4 HANA Cloud is returning the dates with this format: /Date(253402214400000)/

Here is an image where the error happens:

Does anyone have the same error?

Does exist any fix?

Thanks in advance

View Entire Topic
jsg24582
Explorer

Hi mariatrinidad.martinezgea,

Here is the code that is doing the magic 🙂

function ODataV2toODataV4DateTime(value){
    const groups = value.match(/\/Date\((?<arg>.*)\+.*\)\//).groups
    if (!groups)
        return value
    return new Date(Number(groups.arg))
        .toISOString()
}

Best regards.

Trinidad
Product and Topic Expert
Product and Topic Expert

Thank you Juan!

I just did some small changes as the groups option didn't work in my case.
I took your transformation from Number to ISO, thanks!

The date format I receive from my backend is: '/Date(1605810872000)/'

I share my code here in case other people has the same problems I had 😉

function ODataV2toODataV4DateTime(value) {
 var thenum = value.match(/\d+/)[0];
 if (!thenum)
     return value 
return new Date(Number(thenum)).toISOString()
}

Best Regards,
Trinidad.