Back to column formats
Column formattingSharePoint Online

Comment Count

This sample adds a visual indicator to a list item, showing the number of comments present on it.

Comment Count formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "position": "relative",
    "height": "42px"
  },
  "attributes": {
    "class": "=if([$_CommentCount]>0,'ms-fontColor-themePrimary','ms-fontColor-neutralTertiary')"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "font-size": "36px"
      },
      "attributes": {
        "iconName": "Message"
      }
    },
    {
      "elmType": "div",
      "txtContent": "=if([$_CommentCount],if([$_CommentCount] > 999, '1k+', [$_CommentCount]),0)",
      "style": {
        "position": "absolute",
        "width": "36px",
        "text-align": "center",
        "font-size": "16px",
        "top": "6px"
      }
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample adds a visual indicator to a list item, showing the number of comments present on it. This is achieved by using the built-in [$_CommentCount] reference, which returns the number of comments on the current item.

screenshot of the sample.

View requirements

This can be added on any column, overwriting its contents. You could, e.g., create an empty Single Line of Text column called Comment Count and format it with this sample.

Column Name Type
Comment Count Single Line of Text.

Video

The solution was demonstrated and recorded in the General M365 Dev SIG call - 18th of March 2021. You can watch the recording on YouTube. Accessing comment information in list formatting and advance form adjustments

Sample

Solution Author(s)
comment-count.json Chris Kent

Version history

Version Date Comments
1.0 March 19, 2021 Initial release
2.0 August 20, 2021 Added readme

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Additional notes