0

I am trying to implement column formatting on a column that can have a value from (1-17)

Pseudocode =IF(value<=4,"Low",
IF(value=5,"Low-Medium", IF(value=6,"Low-Medium",
IF(value=7,"Low-Medium", IF(value=8,"Medium", IF(value=9,"Medium",
IF(value=10,"Medium", IF(value=11,"Medium", IF(value=12,"Medium-High", IF(value=13,"Medium-High",
IF(value=14,"Medium-High", IF(value=15,"Medium-High", IF(value=16,"Medium-High", IF(value>=17,"High"))))))))))))))

Json

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "div",
    "attributes": {
      "class": "=if(@currentField <= 4, 'sp-field-severity--blocked', '',if(@currentField == 5, 'sp-field-severity--warning', ''))"
    },
    "children": [
      {
        "elmType": "span",
        "style": {
          "display": "inline-block",
          "padding": "0 4px"
        },
        "attributes": {
          "iconName": "=if(@currentField <= 70, 'Error', '')"
        }
      },
      {
        "elmType": "span",
        "txtContent": "=if(@currentField <= 4, 'Error', if(@currentField == 5, 'hello'))"
      }
    ]
  }

What am doing wrong? It just shows the json code in the display view

1

Using the JSON formatting below.

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "div",
    "attributes": {
      "class": "=if(@currentField <= 4, 'sp-field-severity--low', if(@currentField<=7 ,'sp-field-severity--good',if(@currentField<=11,'sp-field-severity--warning',if(@currentField<=16,'sp-field-severity--severeWarning','sp-field-severity--blocked'))))"
    },
    "children": [     
      {
        "elmType": "span",
        "txtContent": "=if(@currentField <= 4, 'Low', if(@currentField<=7 ,'Low-Medium',if(@currentField<=11,'Medium',if(@currentField<=16,'Medium-High','High'))))"
      }
    ]
}

enter image description here

1

It looks like you have an issue with your condition statements. The statement if([conditional], [if true do this], [if false do this]) seems to be off a bit.

"class": "=if(@currentField <= 4, 'sp-field-severity--blocked', '',if(@currentField == 5, 'sp-field-severity--warning', ''))"

In the above snippet your false statement is blank and then you have another IF statement which should be where the false statement is.

When I did this just for testing it worked...the conditions need to be tweaked a bit more but it looks to be on the right path.

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "div",
    "attributes": {
      "class": "=if(@currentField <= 4, 'sp-field-severity--blocked', if(@currentField>5,'sp-field-severity--warning','sp-field-severity--low'))"
    },
    "children": [
      {
        "elmType": "span",
        "style": {
          "display": "inline-block",
          "padding": "0 4px"
        },
        "attributes": {
          "iconName": "=if(@currentField <= 70, 'Error', '')"
        }
      },
      {
        "elmType": "span",
        "txtContent": "=if(@currentField <= 4, 'Error', if(@currentField>5 ,'hello','goodby'))"
      }
    ]
  }

I hope that helps you out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.