Forum Discussion
Date field in JSON text column formatting child component shows empty.
- Sep 12, 2022In the end it turned out that adding the referenced date column to the view and converting it to the locale date string resolved the issue. If now I only could hide that entire (not only its value) date column without JSON having an issue.... But for now I can live with the solution (I've page where I show to related views of the same list next to each other, using dynamic filtering on the right one. By adjusting the column widths I can get the used date column out of site in both views. Only at the bottom the horizontal scroll bar shows up).
JPMHuls_Atos What is the data type of [$MigrationDate] column, is it Date & Time?
What is the format of date time in list, mm/dd/yyyy or dd/mm/yyyy (might be based on site language/regional settings)?
Can you try using [$MigrationDate] only instead of toDateString([$MigrationDate])? Let us know if it works for you.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Hi Ganesh,
It's a date only DateTime column, the locale is NL/Netherlands. The odd thing is that it seemed to work with toDateString, then I made a small change which should not break the JSON, and I got an Invalid date error. Removing toDateString and only using [$MigrationDate] suddenly showed the proper (locale) date... However after reopening the view in a new browser, I either get Invalid date or the row with the date is completely missing... It's driving me nuts...
- ganeshsanapSep 12, 2022MVP
JPMHuls_Atos Try using this JSON:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=if([$SiteTemplate] == 'Main', 'Main ID: ', 'Main site: ') + @currentField + '\nID: ' + [$ID] + '\n' + if(Number([$MigrationDate]) != 0, 'Migration scheduled for: ' + [$MigrationDate], '')" }
Make sure you are properly saving the JSON and not just using "Preview" option.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- JPMHuls_AtosSep 12, 2022Copper ContributorIn the end it turned out that adding the referenced date column to the view and converting it to the locale date string resolved the issue. If now I only could hide that entire (not only its value) date column without JSON having an issue.... But for now I can live with the solution (I've page where I show to related views of the same list next to each other, using dynamic filtering on the right one. By adjusting the column widths I can get the used date column out of site in both views. Only at the bottom the horizontal scroll bar shows up).
- ganeshsanapSep 12, 2022MVP
JPMHuls_Atos I suspected this issue (date column not being added to list view) earlier. But, in your original question you said date value was shown once while using original JSON, so I thought you already have date column added to list view.
Also, you cannot remove date column from list view now. This is a known limitation of JSON formatting >> If you want to reference any column in JSON, it should be added to list view to read it's value.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.