How to format a managed metadata column via JSON by matching the GUID?

Olaf Marzocchi 21 Reputation points
2022-04-13T07:43:03.753+00:00

I have a column with managed metadata from the local term store. I want to format each term in a different color, based on the value of the term.

I am very novice so I started with the JSON formatting examples in https://github.com/pnp/List-Formatting/blob/master/column-samples/managed-metadata-tag-icon/managed-metadata-tag-icon-multi-choice.json

I am using the "equality" operator for my comparisons, but I found out that it succeeds only when I apply it to the label, not to the full "label|GUID" tuple or to the GUID alone.

For example, this doesn't work:

{
  "operator": "==",
  "operands": [
    "@currentField",
    "label|GUID"
  ]
}

but this one does:

{
  "operator": "==",
  "operands": [
    "=toString(@currentField)",
    "label"
  ]
}

But the label could change in the future, so I think it is better to use only the GUID for the comparison.

How to extract the GUID from a term and compare only that part to a predefined string, without using the label?

Thanks!

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,068 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,601 Reputation points
    2022-04-13T11:45:30.613+00:00

    Hi @Olaf Marzocchi
    Extracting the GUID from a term and compare only that part to a predefined string is not supported in column formatting, we could only use "label" here. If the label could change in the future, then you need to modify the column formatting for the changed label.


    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.