JSON formatting Sharepoint column

K D 1 Reputation point
2022-04-08T10:27:57.533+00:00

Hello,

I have a Sharepoint column with about 30 different values. These values have 11 digits.

I want to replace these 11 digit values with letters via Json formatting.

Example:
01234567890 = ABC
12345678901 = AAA
23456789012 = BBB

I manage to do this for a single value, here is the code I use:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=replace(@currentField, '01234567890', 'ABC')"
}

However, I also want to replace the other values but I can't find the good "code" (I don't know Json at all).

Could someone please help me?

Thanks in advance,

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

2 answers

Sort by: Most helpful
  1. K D 1 Reputation point
    2022-04-08T19:01:51.953+00:00

    Is it possible that this is not feasible?

    0 comments No comments

  2. Yanli Jiang - MSFT 22,656 Reputation points Microsoft Vendor
    2022-04-11T10:43:32.11+00:00

    Hi @K D ,

    Your needs can be accomplished.
    You can use JSON code as below:

    {
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "=if(@currentField =='01234567890','ABC',if(@currentField =='12345678901','AAA','BBB'))"

    }

    The result is shown below:

    191845-1.png

    191893-2.png

    If you have 30 different values, you can stack the if statements on the basic of my code.

    Thanks,
    Yanli Jiang

    ===========================================

    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.