0

I would like to change the background color of a SharePoint calendar list item when a pattern is entered in the title with JSON coding. for example, if "ABC" is used in the title, then the background color of the appointment is changed to something other than the default. I have tried the below code but it does not work.

 "$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
    "debugMode": true,
    "elmType": "div",
    "Style": {
        "Color": {
            "operator": "?",
            "operands": [
                {
                    "operator": "==",
                    "operands": [
                  {
                  "operator": "toString()",
                  "operands": [
                  "@currentField"
                  ]
                  },"ABC"
                  ]
                                        }, "green"
                ]
               }
               }
               }
1
  • Just to confirm that you are not trying to get the color changed in the calendar view? Commented Apr 10, 2018 at 13:23

1 Answer 1

1

Here is the correct JSON assuming you are trying to columning formatting in the modern list/libraries:

{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
    "class": {
        "operator": "?",
        "operands": [
            {
                "operator": "==",
                "operands": [
                    {
                        "operator": "toString()",
                        "operands": [
                            "@currentField"
                        ]
                    },
                    "ABC"
                ]
            },
            "sp-field-severity--good","nocolor"
        ]
    }
}}

You can replace "nocolor" class with "sp-field-severity--severeWarning" if you want red color for the items not matching the condition i.e 'ABC'.

More details here

4
  • Thank you! It did work for a regular modern list but it is not working for calendar items. are there any solutions to change the background on calendar items based on a text pattern in the title?
    – Maestro
    Commented Apr 10, 2018 at 18:38
  • Column formatting will only work in the modern experience so if you want to display in the Calendar app 'All Events' you will need to changed the default experience to Modern (under list advanced settings). If you want to show colors in the calendar view you need calendar overlays not column formatting. Commented Apr 11, 2018 at 21:29
  • Is it possible to use custom class instead of the pre-defined sp-field-severity--good Commented Jan 15, 2019 at 2:19
  • @Kannan, you could style. Custom class might work if the css is already included on the master page, though I haven't tried this. Commented Apr 17, 2019 at 10:58

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.