Forum Discussion
120 days before a date format row red backgorund and white text
oskarkuus Unfortunately, I did not understand this condition clearly: get a warning with a red row 120 days before the value in "startdate" is equal to todays date
However, you can easily achieve it using SharePoint JSON view formatting. You will have to use the JSON like:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"additionalRowClass": "=if(Number([$StartDate]) == 0, '', if(addDays([$StartDate],-120) <= @now, 'sp-css-backgroundColor-BgRed sp-css-color-WhiteText', ''))"
}
You can change the operator (<=) in above JSON as per your requirements.
Instead of StartDate, use internal name of your SharePoint list date column. 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?
Here I have used Number([$StartDate]) == 0 to check if SharePoint date column is blank or not. You can find other ways to check if SharePoint date & time column is empty or not at: SharePoint JSON formatting: Check if date & time column is blank/empty
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Thanks for your reply, but i can not get this to work.
If i put in this code:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"additionalRowClass": "=if(Number([$Slutdatum]) == 0, '', if(addDays([$Slutdatum],-120) <= @now, 'sp-css-backgroundColor-BgRed sp-css-color-WhiteText', ''))"
}
All text becomes white no matter what the date is set to.
And the background never turns red no matter what the date is set to.
My column name is "Slutdatum".