Forum Discussion

as733y's avatar
as733y
Copper Contributor
Apr 04, 2024
Solved

Sharepint List Column Formatting

Hi,

 

I'm trying to format my General_x0020_Outlook_x0020_incl column to apply the formatting if the date in the column is within the next 45 day.

 

I think I'm really close with the below JSON, but an I using the wrong "operator" to find the date that is 45 days from today?

 

 

 

 

{
  "$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": [
            {
              "operator": ">=",
              "operands": [
                {
                  "operator": "Date()",
                  "operands": [
                    {
                      "operator": "toDateString()",
                      "operands": [
                        {
                          "operator": "Date()",
                          "operands": [
                            "[$General_x0020_Outlook_x0020_incl]"
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "operator": "Date()",
                  "operands": [
                    {
                      "operator": "toDateString()",
                      "operands": [
                        {
                          "operator": "Date()",
                          "operands": [
                            "@now"
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "operator": "<=",
              "operands": [
                {
                  "operator": "Date()",
                  "operands": [
                    {
                      "operator": "toDateString()",
                      "operands": [
                        {
                          "operator": "Date()",
                          "operands": [
                            "[$General_x0020_Outlook_x0020_incl]"
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "operator": "Date()",
                  "operands": [
                    {
                      "operator": "toDateString()",
                      "operands": [
                        {
                          "operator": "Date()",
                          "operands": [
                            "@now+3888000"
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        "sp-css-backgroundColor-BgCoral sp-css-borderColor-CoralFont sp-field-fontSizeSmall sp-css-color-CoralFont",
        "sp-field-fontSizeSmall"
      ]
    }
  },
  "txtContent": "[$General_x0020_Outlook_x0020_incl.displayValue]"
}

 

 

  • as733y you can do it with far fewer lines of JSON and a much simpler syntax to understand:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "background-color": "=if(Number(@currentField) == 0, '', if(@currentField <= addDays(@now, 45), 'darkGoldenRod', if(@currentField > addDays(@now, 45) && @currentField < addDays(@now, 90), 'teal', '#565757')))",
        "color": "white"
      }
    }

     

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User.
    Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

1 Reply

  • Rob_Elliott's avatar
    Rob_Elliott
    Silver Contributor

    as733y you can do it with far fewer lines of JSON and a much simpler syntax to understand:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "background-color": "=if(Number(@currentField) == 0, '', if(@currentField <= addDays(@now, 45), 'darkGoldenRod', if(@currentField > addDays(@now, 45) && @currentField < addDays(@now, 90), 'teal', '#565757')))",
        "color": "white"
      }
    }

     

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User.
    Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

Resources