Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Data formatting for Fields in a table do not work (Jsonata)

Community Beginner ,
Jul 31, 2024 Jul 31, 2024

Refering to this original post about formatting dates in a JSON object using toMillis and fromMillis:

Date formatting / examples of using JSONata expres... - Adobe Community - 13261898

 

This apporach works with dates in the JSON object that are not in an array. If you try to do this using the old table format or new table format, they result in an unexpected result.

 

Consider this data:

{
   "noArrayDate": "2024-12-30T05:00:00Z",
   "details": [
    {
      "unitId": 0,
      "endDate": "2031-01-01T05:00:00Z"
    },
    {
      "unitId": 1,
      "endDate": "2025-01-01T05:00:00Z"
    },
    {
      "unitId": 2,
      "endDate": "2025-01-01T05:00:00Z"
    }
  ]
}

Using the following Word Template, include either the "New Table Format" or the "Old Table Format" and generate the document to see the result.

StevenCWong_0-1722455111196.png

 

with the new table format, you get this (unsupported expression):

 

StevenCWong_1-1722455172694.png

New Table Format

Unit

Start date

Start date Formatted

 

{% table-start details %}

{{unitId}}

{{endDate}}

{{ $fromMillis($toMillis(endDate),'[D]/[M]/[Y]') }}

{% table-end %}

 

 

with the old table format you get this (format as text - ignored):

StevenCWong_2-1722455229495.png

Old Table Format

Unit

Start date

Start date Formatted

 

{{details.unitId}}

{{details.endDate}}

{{ $fromMillis($toMillis(details.endDate),'[D]/[M]/[Y]’) }}

 

 

Note that formatting dates NOT in an array works fine:

Dates outside of an Array

{{ $fromMillis($toMillis(noArrayDate), '[D]/[M]/[Y]') }}

{{ $fromMillis($toMillis(noArrayDate), '[FNn], [D1o] [MNn] [Y]') }}

 

Is there a proper way to reference the date field in an array?

 

We need to use the same JSON object to support different templates which require different date formats for the same field. 

 

Thanks for any pointers.

 

 

 

TOPICS
Document Generation API
275
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2024 Jul 31, 2024

@Michael MQ thought i'd tag you in case this applies to you too. Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 31, 2024 Jul 31, 2024

I can't test this second, but what if, using the new format, maybe try: 

 

$fromMillis($toMillis(endDate:eval(details)),'[D]/[M]/[Y]')

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2024 Jul 31, 2024

with the :eval(details):

Error: "Please provide the valid/supported input document template"

 

StevenCWong_0-1722457666456.png

 

Thanks

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 31, 2024 Jul 31, 2024

Yeah shoot. To be fair, that was the solution for - I'm looping inside a loop and need to provide a way to reference the right loop. 

 

Unfortunately, you may be out of luck. Of course, you can always just format your numbers _before_ you call DocGen. That's a solution you can do rather quickly. 

 

I'll make a small reproducable case for this and log a bug.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 31, 2024 Jul 31, 2024

It looks like I may have already reported it a few years ago. 😕 

 

https://community.adobe.com/t5/acrobat-services-api-discussions/date-formatting/td-p/12173140

 

I'll check. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 31, 2024 Jul 31, 2024

Ok, so the example of fromMillis and toMillis *does* work on $now, but not an array value, as I beliieve you saw - it's just an issue with the arrays. I filed a new bug.

 

As I said though, you can format locally. If you are using Node.js and need an example, let me know. Intl makes it super easy.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2024 Jul 31, 2024
LATEST

Thanks @Raymond Camden , i appreciate you following up on the bug. 

 

for our purposes, we will need to format the date differently based on the type of report created with the data. Some reports need March 2024, some reports need 03-31-2024, etc.

 

We would have to add a field to the array for each format type a user could possibly need in their report multipiled by each date field in the array.

 

I'll keep an eye out for future updates. Cheers.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources