2

This is about JSON formatted views (not columns) in modern SharePoint online.

List A has a Yes/No field. The values show as Yes or No in the view. When I format the view and show the field value using "txtContent": "[$MyField]", it shows as true or false. (the screenshot has two of these side by side, several records)

enter image description here

In order to conditionally format the elements, I can use the field on its own, since it evaluates to True or False. No operator required.

"class": "=if([$MyField],'sp-field-severity--good','sp-field-severity--blocked')"

List B also has a Yes/No field. The values show as Yes or No in the view. When I format the view and show the field value using "txtContent": "[$MyYesNoField]", it shows as Yes or No.

enter image description here

In order to conditionally format the elements, I have to use a comparison operator and compare with Yes or No as text strings:

"class": "=if([$MyYesNoField]=='Yes','sp-field-severity--good','sp-field-severity--blocked')"

What causes the difference between these two columns in the two different lists and how can it be influenced?

When I download the lists to Excel, the columns all show True/False.

Both lists are populate with a Flow that sets the column values to True/False, not Yes/No.

The problem is that a condition in JSON that is based on the value of the yes/no field will work fine if it is a true/false value, but the view will not render correctly in a list web part when the value is Yes/No and the condition needs to compare with text.

Therefore, I need the Yes/No column to internally store the values as TRUE/FALSE, not as Yes/No.

Any ideas?

| improve this question | | | | |
  • Can you please check again if it is Yes/No field or Choice field? Also, what is the template you are using for both lists? Is there any specific differences in both columns settings?? – Ganesh Sanap Nov 5 '19 at 4:56
  • @Ganeshsanap Believe me, I checked. It’s a yes/no field. No list template. Column in list A was added via the modern view UI in the view. Column in list B was added via the list Settings >add column command. – teylyn Nov 5 '19 at 7:49
2

I followed the same steps to create two Yes/No columns, one from modern view (named FromView) and another from list settings page(named FromSettings).

Tried below combinations and it is working fine for me:

Yes/No column created from Modern View:

{
    "schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
    "hideSelection": true,
    "hideColumnHeader": true,
    "rowFormatter": {
        "elmType": "div",
        "txtContent": "[$FromView]",
        "attributes": {
        "class": "=if([$FromView], 'sp-field-severity--good','sp-field-severity--blocked')"
        }
    }
}

Output:

enter image description here

Yes/No column created from List settings Page:

{
  "hideSelection": true,
  "hideColumnHeader": true,
  "rowFormatter": {
    "elmType": "div",
    "txtContent": "[$FromSettings]",
    "attributes": {
      "class": "=if([$FromSettings], 'sp-field-severity--good','sp-field-severity--blocked')"
    }
  }
}

Output:

enter image description here

| improve this answer | | | | |
  • Thanks. I added more Yes/No columns to the list. They all show as Yes or No in the Json formatter. Must be something wrong with that list. – teylyn Nov 5 '19 at 19:51
  • Is it normal modern SharePoint List or any other type of list? – Ganesh Sanap Nov 6 '19 at 2:17
  • Normal list. Create with New > List. It's probably corrupt. I created another list that doesn't have the problem and have abandoned this one. – teylyn Nov 6 '19 at 10:33
  • Please accept it as an Answer if it helped you. – Ganesh Sanap Dec 13 '19 at 10:06

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.