0

The code below I want use to change color of the column Date according to the current date.

But instead it gives me a error. Can somebody give me a hint?

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "@currentField",
  "style": {
    "color": "=if([$Date] < @now, '#ff0000', if($Date] = @now; '#008000', if([$Date] > @now; '#0000FF')))"
  }
}
1

2 Answers 2

0

I believe this reference will help, its the recent jJSON Schema updates.

can you try this structure?

{
    "type": "integer",
    "minimum": 1,
    "maximum": 1000,
    "if": { "minimum": 100 },
    "then": { "multipleOf": 100 },
    "else": {
        "if": { "minimum": 10 },
        "then": { "multipleOf": 10 }
    }
}

let me know if this helps, Happy learning!

0

There are some syntax errors in your JSON code. Try using below code:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "style": {
        "color": "=if([$Date] < @now, '#ff0000', if([$Date] == @now, '#008000', if([$Date] > @now, '#0000FF', '')))"
    }
}

Note:

  1. You need to add this JSON code on the field for which you want to change the color.
  2. You need to use the internal name of your SharePoint column in JSON code (For Date column). You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

Reference:

Use column formatting to customize SharePoint

Also, there will be very rare cases where your date column will be exactly equal to @now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.