JSON Formatting Text to a Choice Pill
Hi Guys,
I have a very simple thing I just can’t work out how to do. I have a column called Warranty Expiration with a date. I have a Status field with very simple JSON formatting:
{
“$schema”: “https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,
“elmType”: “div”,
“children”: [
{
“elmType”: “span”,
“style”: {
“color”: “=if([$WarrantyExpiration] <= @now, ‘red’, if([$WarrantyExpiration] < @now + 2592000000, ‘orange’, ‘green’))”
},
“txtContent”: “=if([$WarrantyExpiration] <= @now, ‘Expired’, if([$WarrantyExpiration] < @now + 2592000000, ‘Due Soon’, ‘Current’))”
}
]
}
and it’s working fine … I have green text ‘Current’ for anything longer than 30 days away, Orange for under 30 days, and Red for Expired.
Ideally what I’d like is instead of just coloured text, is to have some coloured choice like pills i.e. Green Pill with Current written in it, Orange Pill with Due Soon, and a Red Pill saying expired.
Sounds simple – but I have no idea. Any help is appreciated! 😉
Hi Guys,I have a very simple thing I just can’t work out how to do. I have a column called Warranty Expiration with a date. I have a Status field with very simple JSON formatting:{
“$schema”: “https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,
“elmType”: “div”,
“children”: [
{
“elmType”: “span”,
“style”: {
“color”: “=if([$WarrantyExpiration] <= @now, ‘red’, if([$WarrantyExpiration] < @now + 2592000000, ‘orange’, ‘green’))”
},
“txtContent”: “=if([$WarrantyExpiration] <= @now, ‘Expired’, if([$WarrantyExpiration] < @now + 2592000000, ‘Due Soon’, ‘Current’))”
}
]
} and it’s working fine … I have green text ‘Current’ for anything longer than 30 days away, Orange for under 30 days, and Red for Expired. Ideally what I’d like is instead of just coloured text, is to have some coloured choice like pills i.e. Green Pill with Current written in it, Orange Pill with Due Soon, and a Red Pill saying expired.Sounds simple – but I have no idea. Any help is appreciated! 😉 Read More