How can I apply conditional formatting in calendar view to an MS list to change colours of list entries based on a different column? - JSON code not working

Buttons22 0 Reputation points
2023-01-20T11:34:56.4966667+00:00

I don't understand why my question was deleted before. I was told to post here by Rhoda Zhong - Microsoft Community Moderator and post my question. So I'll try again. Having trouble with entering tags, but I'll do my best.

Hi

I have tried to edit some JSON code to change the colour of list entries in calendar view - the wizard only allows me to apply conditional formatting to the title or date fields, so I edited the JSON code to apply to the name of a different column - "activity". But for some reason it doesn't do anything in my calendar entries. Can anyone help? I've made sure the spelling of the criteria is correct and the name of the field is spelled correctly.

I'm using Microsoft 365 and editing the calendar via the app in my browser. Using Chrome.

Here is my JSON code, which I created by using the wizard initially using the "Title" field and then I change the word "Title" to "Activity" as the name of the field/column I want the conditional formatting to use. Thanks in advance.

{

"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",

"additionalEventClass": {

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Awareness Days / Weeks / Months"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgBlue' , 'sp-css-backgroundColor-BgCornflowerBlue sp-css-color-CornflowerBlueFont')",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Publication"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgGreen' , 'sp-css-backgroundColor-BgMintGreen sp-css-color-MintGreenFont')",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Blog"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgBrown' , 'sp-css-backgroundColor-BgGold sp-css-color-GoldFont')",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Podcast"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkRed' , 'sp-css-backgroundColor-BgCoral sp-css-color-CoralFont')",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Newsletter/Gov Del"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgTeal' , 'sp-css-backgroundColor-BgCyan sp-css-color-CyanFont')+' sp-field-fontSizeSmall'",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Conference"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgOrange' , 'sp-css-backgroundColor-BgPeach sp-css-color-PeachFont')+' sp-field-fontSizeSmall'",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Meeting"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkPink' , 'sp-css-backgroundColor-BgLilac sp-css-color-LilacFont')+' sp-field-fontSizeSmall'",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Event"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkGreen' , 'sp-css-backgroundColor-BgSage sp-css-color-SageFont')+' sp-field-fontSizeSmall'",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Email"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgLavender' , 'sp-css-backgroundColor-BgLightPurple sp-css-color-LightPurpleFont')+' sp-field-fontSizeSmall'",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Activity]",

"Add to comms plan"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkPurple' , 'sp-css-backgroundColor-BgViolet sp-css-color-VioletFont')+' sp-field-fontSizeSmall'",

{

"operator": ":",

"operands": [

{

"operator": "==",

"operands": [

"[$Type of Activity / Action]",

"Revisit for decision"

]

},

"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkBlue' , 'sp-css-backgroundColor-BgLightBlue sp-css-color-LightBlueFont')+' sp-field-fontSizeSmall'",

""

]

}

]

}

]

}

]

}

]

}

]

}

]

}

]

}

]

}

]

}

]

}

}

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Xuyan Ding - MSFT 7,601 Reputation points
    2023-01-23T02:58:49.5833333+00:00

    Hi @Buttons22 ,

    I created by using the wizard initially using the "Title" field and then I change the word "Title" to "Activity" as the name of the field/column I want the conditional formatting to use.

    According to your description, you are renaming the column named Title to Activity. The original internal field of this column is still Title Even if it is renamed, [$Title] should be used when applying to JSON code, because JSON should use the internal field value of the column.

    MicrosoftTeams-image (52)

    Of course, this is a point I found. If it still doesn’t work after the change, you’d better provide more detailed information, such as changing the format conditions and information about other columns you use, etc., so that we can do some simple tests to help you better. If you can, post some screenshots showing your process or code not working.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


  2. Phaedrus 0 Reputation points
    2023-03-07T08:29:56.9666667+00:00

    Hello, I had the same problem. Find the actual field name by going to list settings and edit column and looking at the URL, I created a list from excel and the name of the column in the background was field2, although it was called "Category" Once I changed the code to field_2 it worked as expected

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.