0

I have 8 projects total in the calendar view. For some reason, only Projects A-E are colorful while F-H stay gray.

Is there something wrong with the code below?

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/calendar-formatting.schema.json",
  "additionalEventClass": "=if([$Section] =='Project A' && @isSelected == false, 'sp-css-backgroundColor-successBackground50 sp-css-color-BlackText sp-css-borderColor-GreenText ms-bgColor-sharedGreenCyan10--hover ms-fontColor-white--hover', if([$Section] =='Project A' && @isSelected == true, 'ms-bgColor-green sp-css-color-WhiteText', if([$Section] =='Project B' && @isSelected == false, 'sp-css-backgroundColor-BgPeach sp-css-color-BlackText sp-css-borderColor-RedText ms-bgColor-sharedRed10--hover ms-fontColor-white--hover', if([$Section] =='Project B' && @isSelected == true, 'sp-css-backgroundColor-redDark sp-css-color-WhiteText', if([$Section] =='Project C' && @isSelected == false, 'sp-css-backgroundColor-BgGold sp-css-color-BlackText sp-css-borderColor-BrownText ms-bgColor-yellow--hover ms-fontColor-white--hover', if([$Section] =='Project C' && @isSelected == true, 'ms-bgColor-sharedOrange10 sp-css-color-BlackText', if([$Section] =='Project D' && @isSelected == false, 'ms-bgColor-communicationTint20 sp-css-color-BlackText sp-css-borderColor-BlueText ms-bgColor-sharedCyanBlue10--hover ms-fontColor-white--hover', if([$Section] =='Project D' && @isSelected == true, 'sp-css-backgroundColor-BlueText sp-css-color-WhiteText', if([$Section] =='Project E' && @isSelected == false, 'sp-css-backgroundColor-BgLilac sp-css-color-BlackText sp-css-borderColor-DarkPurpleText ms-bgColor-sharedBlueMagenta20--hover ms-fontColor-white--hover', if([$Section] =='Project E' && @isSelected == true, 'sp-css-backgroundColor-BgPurple sp-css-color-WhiteText', if(@isSelected == false, 'sp-css-backgroundColor-neutralBackground20 sp-css-color-BlackText ms-bgColor-neutralTertiaryAlt--hover ms-fontColor-black--hover', 'sp-css-backgroundColor-neutralTertiary sp-css-color-WhiteText', if([$Section] =='Project F' && @isSelected == false, 'sp-css-backgroundColor-BgLightPurple sp-css-color-BlackText sp-css-borderColor-PurpleText ms-bgColor-sharedMagenta10--hover ms-fontColor-white--hover', if([$Section] =='Project F' && @isSelected == true, 'sp-css-backgroundColor-Purple sp-css-color-WhiteText', if([$Section] =='Project G' && @isSelected == false, 'sp-css-backgroundColor-BgCyan sp-css-color-BlackText sp-css-borderColor-TealText ms-bgColor-sharedGreenCyan10--hover ms-fontColor-white--hover', if([$Section] =='Project G' && @isSelected == true, 'sp-css-backgroundColor-CyanFont sp-css-color-WhiteText', if([$Section] =='Project H' && @isSelected == false, 'sp-css-backgroundColor-BgLightGray30 sp-css-color-BlackText sp-css-borderColor-GrayText ms-bgColor-sharedGray10--hover ms-fontColor-white--hover', if([$Section] =='Project H' && @isSelected == true, 'sp-css-backgroundColor-neutralSecondary sp-css-color-WhiteText')))))))))))))))))"
}

enter image description here

enter image description here

4
  • For which projects/conditions it is not working? Commented Feb 20, 2023 at 9:44
  • @GaneshSanap Project A-E works just fine. It's F-H I am having issues with. I will update the post.
    – Nanu
    Commented Feb 21, 2023 at 14:27
  • You have one extra condition before project F which is causing this issue, try removing it. Commented Feb 23, 2023 at 6:41
  • Try JSON in my answer below. Let me know if it works for you. Commented Feb 23, 2023 at 14:10

1 Answer 1

1

You have one extra condition before Project F conditions (if(@isSelected == false) which is causing this issue, try moving it at the end like below:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/calendar-formatting.schema.json",
  "additionalEventClass": "=if([$Section] =='Project A' && @isSelected == false, 'sp-css-backgroundColor-successBackground50 sp-css-color-BlackText sp-css-borderColor-GreenText ms-bgColor-sharedGreenCyan10--hover ms-fontColor-white--hover', if([$Section] =='Project A' && @isSelected == true, 'ms-bgColor-green sp-css-color-WhiteText', if([$Section] =='Project B' && @isSelected == false, 'sp-css-backgroundColor-BgPeach sp-css-color-BlackText sp-css-borderColor-RedText ms-bgColor-sharedRed10--hover ms-fontColor-white--hover', if([$Section] =='Project B' && @isSelected == true, 'sp-css-backgroundColor-redDark sp-css-color-WhiteText', if([$Section] =='Project C' && @isSelected == false, 'sp-css-backgroundColor-BgGold sp-css-color-BlackText sp-css-borderColor-BrownText ms-bgColor-yellow--hover ms-fontColor-white--hover', if([$Section] =='Project C' && @isSelected == true, 'ms-bgColor-sharedOrange10 sp-css-color-BlackText', if([$Section] =='Project D' && @isSelected == false, 'ms-bgColor-communicationTint20 sp-css-color-BlackText sp-css-borderColor-BlueText ms-bgColor-sharedCyanBlue10--hover ms-fontColor-white--hover', if([$Section] =='Project D' && @isSelected == true, 'sp-css-backgroundColor-BlueText sp-css-color-WhiteText', if([$Section] =='Project E' && @isSelected == false, 'sp-css-backgroundColor-BgLilac sp-css-color-BlackText sp-css-borderColor-DarkPurpleText ms-bgColor-sharedBlueMagenta20--hover ms-fontColor-white--hover', if([$Section] =='Project E' && @isSelected == true, 'sp-css-backgroundColor-BgPurple sp-css-color-WhiteText', if([$Section] =='Project F' && @isSelected == false, 'sp-css-backgroundColor-BgLightPurple sp-css-color-BlackText sp-css-borderColor-PurpleText ms-bgColor-sharedMagenta10--hover ms-fontColor-white--hover', if([$Section] =='Project F' && @isSelected == true, 'sp-css-backgroundColor-Purple sp-css-color-WhiteText', if([$Section] =='Project G' && @isSelected == false, 'sp-css-backgroundColor-BgCyan sp-css-color-BlackText sp-css-borderColor-TealText ms-bgColor-sharedGreenCyan10--hover ms-fontColor-white--hover', if([$Section] =='Project G' && @isSelected == true, 'sp-css-backgroundColor-CyanFont sp-css-color-WhiteText', if([$Section] =='Project H' && @isSelected == false, 'sp-css-backgroundColor-BgLightGray30 sp-css-color-BlackText sp-css-borderColor-GrayText ms-bgColor-sharedGray10--hover ms-fontColor-white--hover', if([$Section] =='Project H' && @isSelected == true, 'sp-css-backgroundColor-neutralSecondary sp-css-color-WhiteText', if(@isSelected == false, 'sp-css-backgroundColor-neutralBackground20 sp-css-color-BlackText ms-bgColor-neutralTertiaryAlt--hover ms-fontColor-black--hover', 'sp-css-backgroundColor-neutralTertiary sp-css-color-WhiteText')))))))))))))))))"
}

Output:

List View (data):

enter image description here

Calendar View:

enter image description here

2
  • 1
    it worked! Thank you!
    – Nanu
    Commented Feb 24, 2023 at 21:29
  • You're welcome! Glad it worked for you. Commented Feb 25, 2023 at 3:14

Your Answer

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

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