Back to column formats
Column formattingSharePoint Online

Multi person favorite

Mark a list item as a favorite

Multi person favorite 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",
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "=if(indexOf(@currentField.email , @me)>-1,'none','flex')",
        "align-items": "center",
        "margin": "3px"
      },
      "attributes": {
        "class": "ms-Link ms-fontColor-themePrimary"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "INTERNALCOLUMNNAME": "=appendTo(@currentField.email , @me)"
        }
      },
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "iconName": "FavoriteStarFill"
          }
        },
        {
          "elmType": "span",
          "txtContent": "Favorite",
          "style": {
            "margin-left": "4px"
          }
        }
      ]
    },
    {
      "elmType": "div",
      "style": {
        "display": "=if(indexOf(@currentField.email, '@me') > -1, 'flex', 'none')",
        "align-items": "center",
        "margin": "3px"
      },
      "attributes": {
        "class": "ms-Link ms-fontColor-themePrimary"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "INTERNALCOLUMNNAME": "=removeFrom(@currentField.email , @me)"
        }
      },
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "iconName": "Unfavorite"
          }
        },
        {
          "elmType": "span",
          "txtContent": "Remove Favorite",
          "style": {
            "margin-left": "4px"
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates the use of the "setValue" and "customRowAction" to let a user add a list item as a favorite in a multi-person column.

screenshot of the sample

[!NOTE]
INTERNALCOLUMNNAME in the code must be re-named to the internal column name.

View requirements

  • This format can be applied to a Multi-Person Column
  • To get most out of the formatting, create a new view filtered on the 'Favorite' column to [@me]

Sample

Solution Author(s)
multi-person-favorite.json Alexander Henkel

Version history

Version Date Comments
1.0 July 31, 2023 Initial release

Additional notes

The sample is based on Assign To Me example by Tetsuya Kawahara

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.