Share via

SharePoint JSON Code Error

Ninx 1 Reputation point
2021-04-11T20:09:54.523+00:00

I am getting the following error in one of my cells when I try to write my own code into SharePoint :

"Failure: Method Date.prototype.toLocaleString called on incompatible receiver [object Object]"

The following is my code:

{

"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",

"elmType": "div",

"debugMode": true,

"txtContent": "@currentField",

"attributes": {

"class": "= if(Number(@currentField) == 0, '' , if(@currentField< [$Date], 'sp-css-backgroundColor-blockingBackground50', ''))"

}

}

Microsoft 365 and Office | SharePoint | For business | Windows

1 answer

Sort by: Most helpful
  1. ZhengyuGuo 10,591 Reputation points Moderator
    2021-04-12T03:02:40.927+00:00

    Hi @Ninx ,

    Assuming that the "@currentField" and "[$Date]" are both Date and Time Column, then the Json Column formatting in the question is working as expected per my test:

    @currentField( named "Test" for example):

    86694-snipaste-2021-04-12-11-00-52.png

    [$Date]:

    86676-snipaste-2021-04-12-11-01-05.png

    86693-snipaste-2021-04-12-10-58-17.png

    Thanks
    Best Regards


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.