Hoping someone can help. I have been working on this issue for a few days now (lots of googling and playing with the code formatting).
What I'm trying to accomplish: I have a sharepoint site to track the status of items and am trying to format the rows of data using the $Expiration (date) column. Depending on the date listed in the expiration I would like the rows to come up in different colors so that as the expiration date approaches the colors change to progressively more red.
Below is the code so far... I have tried other versions but none are performing as expected.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
"if": {
"operator": ">",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"[$Expiration]"
]
}
]
}
]
},
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "+",
"operands": [
"@now",
15768000000
]
}
]
}
]
}
]
}
]
},
"then": {
"additionalRowClass": "sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont"
},
"else": {
"if": {
"operator": ">=",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"[$Expiration]"
]
}
]
}
]
},
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "+",
"operands": [
"@now",
7776000000
]
}
]
}
]
}
]
}
]
},
"then": {
"additionalRowClass": "sp-css-backgroundColor-BgGold sp-field-fontSizeSmall sp-css-color-GoldFont"
},
"else": {
"if": {
"operator": ">=",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"[$Expiration]"
]
}
]
}
]
},
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"@now"
]
}
]
}
]
}
]
},
"then": {
"additionalRowClass": "sp-css-backgroundColor-BgCoral sp-field-fontSizeSmall sp-css-color-CoralFont"
},
"else": {
"additionalRowClass": "sp-css-backgroundColor-redDark sp-field-fontSizeSmall sp-css-color-redDarkFont"
}
}
}
}
Yes, I have looked at the samples given and have tried using the excel formatting:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
"additionalRowClass": "=if(([$Expiration] >= (@now + 15768000000)),'sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont', if([$Expiration] >= (@now + 7776000000)),'sp-css-backgroundColor-BgGold sp-field-fontSizeSmall sp-css-color-GoldFont', if([$Expiration] >= @now),'sp-css-backgroundColor-BgCoral sp-field-fontSizeSmall sp-css-color-CoralFont','sp-css-backgroundColor-redDark sp-field-fontSizeSmall sp-css-color-redDarkFont')"
}
But again this doesn't work as expected either. I know the JSON formatting is correct, but it still will not change the rows as intended.
Any help is appreciated.
if
,then
, andelse
are not valid JSON properties in formatting. Excel style expressions and view formatting (rowFormatter and additionalRowClass) are not supported in SP2019. Please edit your question to include the version of SharePoint you are using and to state what your format rules are (X number of days after/before expiration color should be etc.)