SP List - conditional formatting - based on attachments column

Jade Nel 21 Reputation points
2022-09-15T13:24:09.313+00:00

Hi there,
I am trying to add conditional formatting to my list that highlights the row red when there are no attachments.
I tried setting conditional formatting for if another column was blank and then changing the column name in the JSON code to Attachments, but it did not work.
Please help with what could work for this. I see the attachment column is supported by conditional formatting but it does not come up as an option to select when adding conditional formatting the "code free" way.

Appreciate any tips I can get! :)

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,628 questions
{count} votes

Accepted answer
  1. Renjie Sun-MSFT 2,846 Reputation points Microsoft Employee
    2022-09-16T06:44:14.19+00:00

    Dear @Jade Nel ,

    Thank you for your post in our forum.

    According to the testing and research, the attachment column is not supported in JSON, so you cannot use JSON to determine whether the attachment column is empty.
    You could only use JSON to get the existing column to use column format.

    Should you have any questions or concerns, please do feel free to contact me.

    Yours sincerely,
    Renjie Sun


    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 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-04-26T18:53:42.2+00:00

    You can add JSON Formatting to the Attachments field in SharePoint but MS doesn't make it easy.

    1. Go to List Settings
    2. Click on the Title field
    3. At the end of the URL, change the word Title to Attachments and hit return

    User's image

    1. Add the following to your Column formatting box. This will turn the color red and center the Attachments icon:
    { 
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "div",  "attributes": {
    "class": "=if(@currentField == true, 'sp-field-severity--good', 'sp-field-severity--blocked') + ' ms-fontColor-neutralSecondary'"
    },
    
    "children": [
    {
      "elmType": "span",
      "style": {
        "width": "100%",
        "text-align": "center",
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "Attach"
      }
    }
      ]
    }
    
    1. Press the OK button to save this change.
    1 person found this answer helpful.

  2. Micca 156 Reputation points
    2022-09-19T16:03:19.327+00:00

    @Jade Nel ,

    If I got you right, you would like to highlight a complete list row in red, in case there is no attachment available.

    You might try the following steps to figure out your desired row formatting

    Try it out with a simple text column first:
    242585-image.png

    Then mimic this within a rule for a conditional list row format
    242557-image.png

    Then switch to the advanced formatting options at the bottom and the structure of your JSON code is there for further adjustment
    242631-image.png

    Replace accordingly or by what you have evaluated with the simple text column already:
    242547-image.png

    ending up with:

    {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",  
      "additionalRowClass": {  
        "operator": ":",  
        "operands": [  
          {  
            "operator": "==",  
            "operands": [  
              "[$Attachments]",  
              "0"  
            ]  
          },  
          "sp-field-severity--blocked",  
          ""  
        ]  
      }  
    }