<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: CAPM - External Service - Error When Consuming Date Fields in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176543#M4553709</link>
    <description>&lt;P&gt;Dear Juan,&lt;/P&gt;&lt;P&gt;Thanks for reporting this. We'll look into it.&lt;/P&gt;&lt;P&gt;For now, I'm afraid you'll need to do the conversion yourself.&lt;BR /&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jun 2020 06:32:08 GMT</pubDate>
    <dc:creator>david_kunz2</dc:creator>
    <dc:date>2020-06-04T06:32:08Z</dc:date>
    <item>
      <title>CAPM - External Service - Error When Consuming Date Fields</title>
      <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaq-p/12176542</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I am developing a solution using CAPM.&lt;/P&gt;
  &lt;P&gt;I am using the S/4 HANA Cloud API API_JOURNALENTRYITEMBASIC_SRV as an external service.&lt;/P&gt;
  &lt;P&gt;My problem is when I try to consume an EntitySet that returns an attribute of tipe Edm.Date (for example A_CostCenter entityset).&lt;/P&gt;
  &lt;P&gt;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."&lt;/P&gt;
  &lt;P&gt;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)/&lt;/P&gt;
  &lt;P&gt;Here is an image where the error happens:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1812166-capm-external-service-error-when-consuming-date-fi.png" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;IMG alt="" /&gt;Does anyone have the same error?&lt;/P&gt;
  &lt;P&gt;Does exist any fix?&lt;/P&gt;
  &lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 00:03:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaq-p/12176542</guid>
      <dc:creator>jsg24582</dc:creator>
      <dc:date>2020-06-04T00:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: CAPM - External Service - Error When Consuming Date Fields</title>
      <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176543#M4553709</link>
      <description>&lt;P&gt;Dear Juan,&lt;/P&gt;&lt;P&gt;Thanks for reporting this. We'll look into it.&lt;/P&gt;&lt;P&gt;For now, I'm afraid you'll need to do the conversion yourself.&lt;BR /&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 06:32:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176543#M4553709</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2020-06-04T06:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: CAPM - External Service - Error When Consuming Date Fields</title>
      <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176544#M4553710</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;Thank you for your response.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I think the problem is that the framework is not considering that the external service is OData 2.0.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;B&gt;Then it tries to parse an OData 2.0 JSON Date as an OData 4.0 JSON Date, and the format is very different.&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Do you have any suggestion to do the conversion myself?&lt;/P&gt;&lt;P&gt;I am doing the following to fordward the requests to the external services:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const cds = require('@sap/cds')

module.exports = cds.service.impl(async function () {

    const journalEntryItemBasicSrv = await cds.connect.to('API_JOURNALENTRYITEMBASIC_SRV')
    const { A_CompanyCode, A_GLAccountInChartOfAccounts, A_CostCenter } = this.entities

    const entities = [ A_CompanyCode, A_GLAccountInChartOfAccounts, A_CostCenter ]
    entities.forEach( entity =&amp;gt; {
        this.on('READ', entity, req =&amp;gt; journalEntryItemBasicSrv.tx(req).run(req.query))
    });
})

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 13:25:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176544#M4553710</guid>
      <dc:creator>jsg24582</dc:creator>
      <dc:date>2020-06-04T13:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: CAPM - External Service - Error When Consuming Date Fields</title>
      <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176545#M4553711</link>
      <description>&lt;P&gt;David,&lt;/P&gt;&lt;P&gt;I find the way to do the conversion (basically the `run` method returns a Promise that its resolved value is the JSON response of the external service, already parsed, without doing any validation):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;        this.on('READ', entity, async req =&amp;gt; {
            let response = await journalEntryItemBasicSrv.tx(req).run(req.query)
            response.forEach( instance =&amp;gt; {
                if (instance.ValidityEndDate) 
                instance.ValidityEndDate = ODataV2toODataV4Date(instance.ValidityEndDate)
            });
            return response;
        })
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It would be very helpful if the problem is fixed.&lt;/P&gt;&lt;P&gt;Thanks a lot for your support!&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 14:06:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176545#M4553711</guid>
      <dc:creator>jsg24582</dc:creator>
      <dc:date>2020-06-04T14:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: CAPM - External Service - Error When Consuming Date Fields</title>
      <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176546#M4553712</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;jsg24582&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Could you please share the ODataV2toODataV4Date function implementation?&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt;  Do you know if this issue is going to be fixed soon?&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Trinidad.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 15:11:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176546#M4553712</guid>
      <dc:creator>Trinidad</dc:creator>
      <dc:date>2020-12-21T15:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: CAPM - External Service - Error When Consuming Date Fields</title>
      <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176547#M4553713</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;mariatrinidad.martinezgea&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Here is the code that is doing the magic &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;function ODataV2toODataV4DateTime(value){
    const groups = value.match(/\/Date\((?&amp;lt;arg&amp;gt;.*)\+.*\)\//).groups
    if (!groups)
        return value
    return new Date(Number(groups.arg))
        .toISOString()
}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Best regards.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 17:14:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176547#M4553713</guid>
      <dc:creator>jsg24582</dc:creator>
      <dc:date>2020-12-21T17:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: CAPM - External Service - Error When Consuming Date Fields</title>
      <link>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176548#M4553714</link>
      <description>&lt;P&gt;Thank you Juan!&lt;/P&gt;&lt;P&gt;I just did some small changes as the groups option didn't work in my case. &lt;BR /&gt;I took your transformation from Number to ISO, thanks!&lt;/P&gt;&lt;P&gt;The date format I receive from my backend is: '/Date(1605810872000)/'&lt;/P&gt;&lt;P&gt;I share my code here in case other people has the same problems I had &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;function ODataV2toODataV4DateTime(value) {
 var thenum = value.match(/\d+/)[0];
 if (!thenum)
     return value &lt;BR /&gt; return new Date(Number(thenum)).toISOString()&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Best Regards,&lt;BR /&gt;Trinidad.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 07:12:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/capm-external-service-error-when-consuming-date-fields/qaa-p/12176548#M4553714</guid>
      <dc:creator>Trinidad</dc:creator>
      <dc:date>2020-12-22T07:12:31Z</dc:date>
    </item>
  </channel>
</rss>

