Forum Discussion

John Duckett's avatar
John Duckett
Copper Contributor
Jan 16, 2019

Conditional formatting using JSON

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-conditional-formatting

 

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

    • John Duckett's avatar
      John Duckett
      Copper Contributor
      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.
      • John Warner's avatar
        John Warner
        Iron Contributor
        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'"
        }
        }

Resources