1

I'm trying to set up conditional formatting on a List for Due Dates (SharePoint online).

I can't seem to get the correct code for Due Date is between today and 5 days from now. If I use an arbitrary date for one of the dates it works, but as soon as I add @now + 432000000 (5 days in milliseconds) it doesn't work.

If I use on or before @now + 432000000 it works so the function to calculate the date isn't the problem.

Code below:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "02px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "&&",
          "operands": [
            {
              "operator": "!=",
              "operands": [
                "[$FileStatus]",
                "Decided"
              ]
            },
            {
              "operator": "&&",
              "operands": [
                {
                  "operator": "=",
                  "operands": [
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            {
                              "operator": "Date()",
                              "operands": [
                                "[$Decision_x0020_Due]"
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            {
                              "operator": "Date()",
                              "operands": [
                                "@now"
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "operator": "=",
                  "operands": [
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            {
                              "operator": "Date()",
                              "operands": [
                                "[$Decision_x0020_Due]"
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "operator": "Date()",
                      "operands": [
                        {
                          "operator": "toDateString()",
                          "operands": [
                            {
                              "operator": "Date()",
                              "operands": [
                                "@now + 432000000"
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        "sp-css-backgroundColor-BgGold sp-css-borderColor-GoldFont sp-field-fontSizeSmall sp-css-color-GoldFont",
        ""
      ]
    }
  },
  "txtContent": "[$File_x0023_]"
}
1
  • Can you explain all your requirements/conditions (add details by editing your original question). JSON you added to your question is messy & not in correct syntax. Mar 31 at 7:29

1 Answer 1

0

As per my understanding by looking at your JSON, I think you need 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"
  },
  "txtContent": "[$File_x0023_]",
  "attributes": {
    "class": "=if([$FileStatus] != 'Decided' && [$Decision_x0020_Due] >= @now && [$Decision_x0020_Due] < addDays(@now,5),'sp-css-backgroundColor-BgGold sp-css-borderColor-GoldFont sp-field-fontSizeSmall sp-css-color-GoldFont','')"
  }
}

Note:

  1. Use correct internal name of your SharePoint list columns, check How to find the Internal name of columns in SharePoint Online?
  2. You can adjust number of days in addDays operator and < or >= conditions as per your requirements.

Your Answer

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

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