Forum Discussion
JTFInc
Apr 09, 2021Copper Contributor
JSON if statement for conditional formatting
I am new at JSON and would like some help on how to write an if statement for conditional formatting in a SharePoint list that will change a columns background (@currentField) color if the Position c...
- Apr 09, 2021
JTFInc you need to use || which stands for or (&& is and) as follows:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "padding-left": "14px", "background-color": "=if([$Position] == 'Chief Cook' || [$Position] =='Cook' || [$Position] == 'Steward' , '#00afff', '#d7dae1')", "color": "black" } }
I've used this JSON to format the Contract column in the image below:
Rob
Los Gallardos
Microsoft Power Automate Community Super User
RobElliott
Apr 09, 2021Silver Contributor
JTFInc you need to use || which stands for or (&& is and) as follows:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"padding-left": "14px",
"background-color": "=if([$Position] == 'Chief Cook' || [$Position] =='Cook' || [$Position] == 'Steward' , '#00afff', '#d7dae1')",
"color": "black"
}
}
I've used this JSON to format the Contract column in the image below:
Rob
Los Gallardos
Microsoft Power Automate Community Super User
carlos_vargas
Jul 07, 2022Copper Contributor
Thank you RobElliott,
Elegant solution and easy to use
I have implemented it this way
"display": "=if(([$Column1] == 'Value1' || [$Column1] == 'Value2') && [$Column2] != 'Value3', 'display', 'none')"