1

I have a SharePoint LIST that's being used to manage events. There are 6 participants for each event and each Participant has a column:

"Participant 1", "Participant 2", "Participant 3", "Participant 4", "Participant 5", "Participant 6"

I need the FILL color of Participant 1-3 to be Green if EMPTY and Transparent if NOT EMPTY I need the FILL color of Participant 4-6 to be YELLOW if EMPTY and Transparent if NOT EMPTY

I have been able to accomplish the above - my issue is that the "[$Evenement]" column has two choices; Orientation/Formation. If the selected choice is Orientation - I need the Participant 4/5 columns to have GREEN fill IF EMPTY and Transparent if NOT EMPTY. Below is the code that's not working for what I need. Any help would be appreciated - I am a complete newbie to JSON.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(@currentField == '', '#98FB98', if(@currentField == 'blocked', '#FF6A6A', if([$Evenement] == 'Orientation', '#FFFF66', '')))"
  }
}

1 Answer 1

0

This should work. You just need nest one if() inside the other like so:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if([$Evenement] == 'Orientation', if(@currentField == '', 'green', 'transparent'), 'transparent')"
  }
}

enter image description here

Update. Final code version

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "debugMode": true,
  "elmType": "div",
  "attributes": {
    "class": "=if(@currentField == '', if([$Evenement] == 'Formation', 'sp-css-backgroundColor-greenLight', if([$Evenement] == 'Orientation','ms-bgColor-sharedYellow10', if(@currentField == 'blocked', 'sp-css-backgroundColor-errorBackground50','transparent'))) ,if(@currentField == 'blocked', 'sp-css-backgroundColor-errorBackground50', '') )"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
} 

enter image description here

10
  • I tried your code and I had tried that myself before but this is what happens: imgur.com/a/s4tfYwX Apr 10, 2021 at 0:02
  • I think I misunderstood your conditions. I've updated the code in the answer. Can you try the new version? Apr 10, 2021 at 0:12
  • Denis, you have no idea how much I appreciate your help - you've brought me half way through!!! thank you!!! I am trying to add two additional conditions in there - 1. IF text is "blocked" change the FILL to RED and 2. IF Evenement is "Formation" then it should be a different FILL like lets say yellow. Apr 10, 2021 at 0:41
  • 1
    imgur.com/a/biDUtVK here you go! Apr 10, 2021 at 18:16
  • 1
    Thank you very much Denis! Not only youve helped me tremendously but youve enabled me to understand this enough to be able to modify it and even add icons with conditions :) Thanks again! Apr 11, 2021 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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