0

Apologies this is my first question so I will summarize the issue as best as possible.

On the list I have created below in the progress column I created a drop down option using choice type. I have 3 options, completed - in progress - overdue. I would like to be able when clicking on completed to remove the red conditional formatting on the Due column which shows red when the date is past.

I thought I could do a simple if statement using 'completed' as the statement to change the formatting but it is not working.

Is my approach to complex?

list

The json in Due column;

    {
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "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-BgDarkRed sp-css-borderColor-WhiteFont sp-field-fontSizeMedium sp-css-color-WhiteFont",
            {
              "operator": ":",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            "@currentField"
                          ]
                        }
                      ]
                    },
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            "@now"
                          ]
                        }
                      ]
                    }
                  ]
                },
                "sp-css-backgroundColor-BgOrange sp-css-borderColor-WhiteFont sp-field-fontSizeMedium sp-css-color-WhiteFont",
                {
                  "operator": ":",
                  "operands": [
                    {
                      "operator": ">",
                      "operands": [
                        {
                          "operator": "Date()",
                          "operands": [
                            {
                              "operator": "toDateString()",
                              "operands": [
                                "@currentField"
                              ]
                            }
                          ]
                        },
                        {
                          "operator": "Date()",
                          "operands": [
                            {
                              "operator": "toDateString()",
                              "operands": [
                                "@now"
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    "sp-css-backgroundColor-BgGreen sp-css-borderColor-WhiteFont sp-field-fontSizeMedium sp-css-color-WhiteFont",
                    ""
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "txtContent": "@currentField.displayValue"
}
4
  • Can you share the current column formatting JSON you are using for "Due" column? I will provide the update JSON based on "Progress" choice column. Commented Feb 22 at 10:03
  • Just added above - thank you.
    – Stevan
    Commented Feb 22 at 10:59
  • Are you using SharePoint Online/Microsoft Lists or SharePoint 2019? Commented Feb 22 at 11:05
  • I'm using MS Lists
    – Stevan
    Commented Feb 22 at 11:08

2 Answers 2

0

Try using JSON like below:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "attributes": {
    "class": "=if(Number(@currentField) == 0 || [$Progress] == 'Completed', '',if(@currentField < @now, 'sp-css-backgroundColor-BgDarkRed sp-css-borderColor-WhiteFont sp-field-fontSizeMedium sp-css-color-WhiteFont', if(@currentField == @now, 'sp-css-backgroundColor-BgOrange sp-css-borderColor-WhiteFont sp-field-fontSizeMedium sp-css-color-WhiteFont', if(@currentField > @now,'sp-css-backgroundColor-BgGreen sp-css-borderColor-WhiteFont sp-field-fontSizeMedium sp-css-color-WhiteFont',''))))"
  },
  "txtContent": "@currentField.displayValue"
}

Where [$Progress] is an internal name of your choice column in SharePoint list in this format: [$InternalNameOfColumn].

You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

Output:

enter image description here

Related read: SharePoint JSON formatting: Check if date & time column is blank/empty

2
  • 1
    Thank you for this and the learning.
    – Stevan
    Commented Feb 22 at 12:13
  • Okay after researching a bit I managed to change the JSON to something a little different. Based on your help so thank you. The choice of internal names seems random to me. I thought the style convention was to UNICODE the name I use but for some reason its using field_5.... I'll investigate more on this.
    – Stevan
    Commented Feb 23 at 10:19
0

I updated the JSON:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            "[$field_4]",
            "Completed"
          ]
        },
        "sp-field-fontSizeMedium sp-css-color-WhiteText",
        "sp-field-fontSizeMedium sp-css-color-BlackText sp-field-bold"
      ]
    }
  },
  "txtContent": "[$field_6.displayValue]"
}

The result now removes the end date when I change in progress to 'Completed'.

enter image description here

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.