Search code examples
jsonsharepointlogic

Multiple IF-statements in JSON AdditionalRowClass


After studying this question and answer, I still can not make my JOSN formula work correctly.

I too moved away from nested JSON, however I'm not opposed of reverting if necessary.

{
 "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
"additionalRowClass": "=if(Number([$Question_x0020_Date]) == 0, 'sp-css-backgroundColor-white',if([$Question_x0020_Date] <= @now &&[$Question_x0020_Asked] == 'No', 'sp-field-severity--warning', if([$Question_x0020_Date] <= @now + 3024000000 && [$Question_x0020_approved] == 'No' , 'sp-field-severity--blocked', '')"
}

However, this formula does not color the rows as they should be colored. In fact, no rows gets any color even though criteria are met.

The nested JSON I did start with, are:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "additionalRowClass": {
    "operator": ":",
    "operands": [
      {
        "operator": "&&",
        "operands": [
          {
            "operator": "==",
            "operands": [
              {
                "operator": "Date()",
                "operands": [
                  {
                    "operator": "toDateString()",
                    "operands": [
                      {
                        "operator": "Date()",
                        "operands": [
                          "[$Question_x0020_Date]"
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                "operator": "Date()",
                "operands": [
                  {
                    "operator": "toDateString()",
                    "operands": [
                      {
                        "operator": "Date()",
                        "operands": [
                          "@now"
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "operator": "==",
            "operands": [
              "[$Question_x0020_Asked]",
              "No"
            ]
          }
        ]
      },
      "sp-css-backgroundColor-BgGold sp-field-fontSizeSmall sp-css-color-GoldFont",
      "sp-css-backgroundColor-white sp-field-fontSizeSmall sp-css-color-LightGrayFont"
    ]
  }
}

... which does return the correct color on correct rows, but it obviuosly only handles the second IF-statement of the first code-snippet:

if([$Question_x0020_Date] <= @now &&[$Question_x0020_Asked] == 'No', 'sp-field-severity--warning'

Is it possible to add more "additionalRowClass" to the JSON? So that each "additionalRowClass" handles each IF-statement? I added the logic for the first part as another "additionalRowClass", but only the latter in the schema/JSON runs.


Solution

  • You could use below rules in the JSON formatting.

    enter image description here

    enter image description here

    enter image description here

    Result:

    enter image description here

    Update:

    enter image description here