Forum Discussion
newbeetle
Oct 20, 2021Copper Contributor
JSON If Statement
Hi I have an If Statement that conditionally formats the background based on a date as follows; "attributes": { "class": "=if(@currentField <= @now,'sp-field-severity--blocked', if(@currentFiel...
- Oct 21, 2021
newbeetle the simpler JSON is:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "background-color": "=if([$Status] == 'Failed', '#7d0000', ((if(@currentField <= @now, 'red', if((@currentField >= @now && @currentField <= @now + 7776000000),'orange','green')))", "color": "white" } }Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
newbeetle
Oct 21, 2021Copper Contributor
Hi Rob,
I see what you mean, I'm very new to JSON but have applied your advice and have utilised an additional column and now have this working.
Many thanks ![]()
RobElliott
Oct 21, 2021Silver Contributor
newbeetle the simpler JSON is:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if([$Status] == 'Failed', '#7d0000', ((if(@currentField <= @now, 'red', if((@currentField >= @now && @currentField <= @now + 7776000000),'orange','green')))",
"color": "white"
}
}
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
- newbeetleOct 21, 2021Copper ContributorThanks Rob, yes that is much easy.