0

I'm new to SharePoint List Conditional Formatting

I've got two columns one is [$Status], and the other is Due Date. If the status is resolved it will be green,

if the status is open and the due date is before @now then red if the status is open and the due date is after @now then yellow if the status is open and the due date is same as @now then yellow.

I currently have this, but I'm unsure of how to add those If statements. Any help would be appreciated! I have the following JSON code right now:

{
  "elmType": "div",
  "style": {
    "padding": "0 4px"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            "@currentField",
            ""
          ]
        },
        "",
        {
          "operator": ":",
          "operands": [
            {
              "operator": "<",
              "operands": [
                {
                  "operator": "Date()",
                  "operands": [
                    {
                      "operator": "toDateString()",
                      "operands": [
                        "@currentField"
                      ]
                    }
                  ]
                },
                {
                  "operator": "Date()",
                  "operands": [
                    {
                      "operator": "toDateString()",
                      "operands": [
                        "@now"
                      ]
                    }
                  ]
                }
              ]
            },
            "sp-css-backgroundColor-errorBackground",
            {
              "operator": ":",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            "@currentField"
                          ]
                        }
                      ]
                    },
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            "@now"
                          ]
                        }
                      ]
                    }
                  ]
                },
                "sp-css-backgroundColor-warningBackground",
                {
                  "operator": ":",
                  "operands": [
                    {
                      "operator": ">",
                      "operands": [
                        {
                          "operator": "Date()",
                          "operands": [
                            {
                              "operator": "toDateString()",
                              "operands": [
                                "@currentField"
                              ]
                            }
                          ]
                        },
                        {
                          "operator": "Date()",
                          "operands": [
                            {
                              "operator": "toDateString()",
                              "operands": [
                                "@now"
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    "sp-css-backgroundColor-warningBackground",
                    ""
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "txtContent": "@currentField"
}
0

I have used something like below

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "@currentField",
  "style": {
    "color": "=if(@currentField == 'Resolved', '#008000', if([$DueDate] < @now , '#ff0000',if([$DueDate] > @now, '#FFFF00', '#00FF00')))"
  }
}

In my example, [DueDate] is the Date column and '[Status]' is a Choice column with 2 values 'Open' and 'Resolved' and this formatting is done in 'Status' column.

Please check the Microsoft documentation for detailed reference.

Here is the one with your version:

{
  "elmType": "div",
  "style": {
    "padding": "0 4px"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            "@currentField",
            "Resolved"
          ]
        },
        "sp-css-backgroundColor-successBackground",
        {
          "operator": ":",
          "operands": [
            {
              "operator": "<",
              "operands": [
               "[$DueDate]",
                "@now"
              ]
            },
            "sp-css-backgroundColor-errorBackground",
            {
              "operator": ":",
              "operands": [
                {
                  "operator": "==",
                   "operands": [
                      "[$DueDate]",
                      "@now"
                    ]
                },
                "sp-css-backgroundColor-warningBackground",
                {
                  "operator": ":",
                  "operands": [
                    {
                      "operator": ">",
                      "operands": [
                          "[$DueDate]",
                          "@now"
                        ]
                    },
                    "sp-css-backgroundColor-warningBackground",
                    ""
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "txtContent": "@currentField"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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