1

I am working on some custom JSON using the "rowFormatter" view formatting schema. I want to display an Icon depending on the value in another Column.

My conditional statement is not working. Any help is appreciated.

"children": [
                {
                    "elmType": "span",
                    "txtContent": "[!DataDomain.DisplayName]",
                    "style": {
                      "display": "block",
                      "color": "#333333",
                      "text-align": "left",
                      "font-size": "12px",
                      "font-weight": "bold",
                      "padding-top": "10px"
                    }
                  },
                  {
                    "elmType": "span",
                    "attributes": {
                      "iconName": "=if ([$DataDomain] == 'Property', 'CityNext', if([$DataDomain]== 'Tenant', 'People', if ([$DataDomain] == 'Financial', 'Financial', if ([$DataDomain] == 'Client', 'AccountManagement', if ([$DataDomain] == 'Employee', 'WorkforceManagement', if ([$DataDomain] == 'Market/External', 'Source'))))))",
                      "class": "ms-fontColor-neutralPrimary"
                    },
                    "style": {
                        "display": "inline"
                    }

                  },
                  {
                    "elmType": "span",
                    "txtContent": "=if ([$DataDomain] == '', '–', [$DataDomain])",
                    "style": { 
                    "display": "inline",
                      "font-size": "12px",
                      "padding-left": "5px"
                    }
                  }
              ]
2
  • What is the data type of your "DataDomain" column? Are you getting any syntax error or it's just that icon is not rendering? May 14 at 14:54
  • I am not getting a syntax error. The icons are just not rendering. May 14 at 15:44
0

Try using this:

"iconName": "=if([$DataDomain] == 'Property', 'CityNext', if([$DataDomain] == 'Tenant', 'People', if([$DataDomain] == 'Financial', 'Financial', if([$DataDomain] == 'Client', 'AccountManagement', if([$DataDomain] == 'Employee', 'WorkforceManagement', if([$DataDomain] == 'Market/External', 'Source', ''))))))"

Also, make sure you are using correct internal name of your "DataDomain" column in JSON.

Documentation:

  1. Use view formatting to customize SharePoint
  2. Use column formatting to customize SharePoint
7
  • This did not work unfortunately. May 14 at 15:46
  • What is the column type/data type of your [$DataDomain] column? May 14 at 16:29
  • Are you using correct internal name? Are you able to see the "DisplayName" of column correctly? May 14 at 16:36
  • Yes. I am using the correct internal name. I am referencing the same column in the "span" immediately below the one with I am having the issue with as you will see in the original code snippet I posted. Is it not possible to use an if statement with the "iconName" attribute? I used a "if" logic statement in another view on "background-color" so I figured it should work with "iconName". May 15 at 2:05
  • if expressions work with iconName as well (check 2nd link in my answer). If everything is correct, it should work for you. Is this column added in your list view? To reference the column in JSON, it should be added to the list view. Also, what is the data type of column? Single line of text or choice or something else? May 15 at 3:48
0

Please use the below column formatting:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "block",
        "color": "#333333",
        "text-align": "left",
        "font-size": "12px",
        "font-weight": "bold",
        "padding-top": "10px",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "=if([$DataDomain] == 'Property', 'CityNext', if([$DataDomain]  == 'Tenant', 'People', if([$DataDomain] == 'Financial', 'Client', if([$DataDomain] == 'Client', 'AccountManagement',if([$DataDomain] == 'Employee','WorkforceManagement',if([$DataDomain] == 'Market/External','Source',''))))))"
      }
    },
    {
      "elmType": "span",
      "txtContent": "=if ([$DataDomain] == '', '–', [$DataDomain])"
    }
  ]
}

enter image description here

1
  • Thank you @EchoDu_MSFT. The issue was not when using the Column formatting schema . I am using the using the row formatting schema. However I think I have gotten it to work? I used the columnFormatterReference to reference the column formatting in the list view. and it works. { "elmType": "span", "columnFormatterReference": "[$DataDomain]", "style": { "display": "inline", "padding-top": "10px" } } May 17 at 12:49

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .