SharePoint 2019 JSON formatting

Antti Astikainen 20 Reputation points
2023-11-28T07:24:52.4+00:00

Could someone tell me, how can I show column with green background if date value is 45 days greater than current date? If data is in this 45 range, show it yellow.

my current JSON: (shows all future date items with green)

  {  
    "operator": ">=",  
    "operands": [  
        "@currentField",  
        "@now",
        {  
            "operator": "+",  
            "operands": [  
            "@now",  
            "3888000000"
            ]  
        }
    ]
  },  
  "sp-field-severity--good",
Microsoft 365 and Office SharePoint Server For business
Microsoft 365 and Office SharePoint For business Windows
{count} votes

Accepted answer
  1. Teddos 80 Reputation points
    2023-12-05T08:50:36.65+00:00

    Hi Antti, my answer is 100% AST. I use it in my SharePoint 2019 environment. You must have made a typo somewhere.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yanli Jiang - MSFT 31,596 Reputation points Microsoft External Staff
    2023-11-29T10:03:56.5766667+00:00

    Hi @Antti Astikainen ,

    You can do this using the IF function:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
      "background-color": "=if(@currentField >= @now+3888000000, 'green',if(@currentField < @now,'white','yellow'))"
      }
    }
    

    The result:User's image

    Hope this is helpful.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


Your answer

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