Conditional formatting using JSON

Copper Contributor

I have tried to customise a column using JSON script lifted from this site 

 

https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#apply-co...

 

and have viewed numerous YouTube videos of people just copying and pasting this code into the Edit columns settings and it just working.  Nothing happens for me however, is there a setting at a high level that needs to be switched on to allow JSON formatting to work?

4 Replies
Have you checked to make sure the field is a number field?
John thank you for the reply, apologies I was a bit vague in the initial description. Is the textual fields I'm looking at doing formatting on - a RAG status that I wasn't to colour red / amber/ green depending on the value in my RAG column.
The copy/paste JSON should work out of the box, no need for anything to be turned on, at least as far as SharePoint Online. You may have to adjust the code depending on values within your column. For instance change the value of YOUR_RAG_STATUS_VALUE in the code below to each possible RAG value for your field :

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--good', if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--low', if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--warning', if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--severeWarning', 'sp-field-severity--blocked')))) + ' ms-fontColor-neutralSecondary'"
}
}
That's what I thought, but nothing happens so then I wondered if it was spacing between the lines (I know literally nothing about JSON so was guessing)

Then I wondered whether it was because it wasn't a standard column, but one I had created.