Forum Discussion
tlangfor
Dec 11, 2024Copper Contributor
Change SharePoint library column JSON to highlight dates in the last 24 hrs to a different colour
I have a SharePoint document library with a "Last Posted Date" column which is updated by a Power Automate flow. I have the "Last Posted Date" column formatted with the JSON below to highlight any f...
Dec 13, 2024
Try this:
{
"$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",
"background-color": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
{
"operator": "-",
"operands": [
{
"operator": "Number",
"operands": [
{
"operator": "Date()"
}
]
},
{
"operator": "Number",
"operands": [
{
"operator": "Date()",
"operands": [
"[$Last_x0020_Posted_x0020_Date]"
]
}
]
}
]
},
86400000
]
},
"darkgreen", // Highlight files posted in the last 24 hours
{
"operator": "?",
"operands": [
{
"operator": "!=",
"operands": [
"[$Last_x0020_Posted_x0020_Date]",
null
]
},
"lightgreen", // Highlight files with a valid date
"transparent" // Default background for files with no date
]
}
]
},
"color": "white"
},
"children": [
{
"elmType": "span",
"style": {
"overflow": "hidden",
"text-overflow": "ellipsis",
"padding": "0 3px"
},
"txtContent": "[$Last_x0020_Posted_x0020_Date.displayValue]"
}
]
}