Apr 08 2021 08:25 PM
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 columns item is selected as Chief Cook, Cook, or Steward . =if([$Position] == 'Chief Cook or Cook or Steward', '#00afff', '')
The JSON below I found on the web works when only 'one' choice is entered. Is there a way to use a character to include the other 2 choices in the syntax?
{
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if([$Position] == 'Cook', '#00afff', '')",
"color": "=if(@currentField >= @now - 94672800000 ,'green', (if(@currentField >= @now - 94672800000, '#ffa59b','red'))"
}
}
Any help would be appreciated.
Apr 09 2021 04:24 AM
Solution@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
Apr 09 2021 04:33 AM
Jul 23 2021 08:28 AM
@RobElliott Hi. I attempted this but I got all the same color as my background. Is this possible to use on a calculated column?
Aug 19 2021 11:44 PM
Jul 07 2022 12:16 PM - edited Jul 07 2022 12:22 PM
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')"
Nov 28 2023 11:49 AM
Hi @RobElliott, hoping you can assist in a similar situation.
I've got a Sharepoint list with folders and excel files that either have a response due date or do not. I want a column field to be visible only if the list entity is an excel file with a listed response due date.
The below JSON has successfully hidden the field for folders, but my second conditional to hide the field if the 'Responses Due' column is blank is not working.
Apr 09 2021 04:24 AM
Solution@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