How do I use a number value field in JSON using "if" condition(s) for SharePoint List formatting a txtContent?

mLantz 20 Reputation points
2023-07-28T12:58:42.56+00:00

I have a list where I'd like to add a first, second, and first place emoji in front of the person's name based on a number "Sort" column. The Sort column has values of "1," "2," and "3" that I would like to use in an "if" conditional format to add 🥇 to first place, 🥈 to second place, and 🥉 place winners' profile titles.

This is what I have so far, and sadly it is returning the first-place emoji🥇to third-place people.

"txtContent": "=if([$Sort] >= 1, '🥇', '' + replace(substring([$Technician_x0020_Profile.title], indexOf([$Technician_x0020_Profile.title], ' ') + 1, indexOf([$Technician_x0020_Profile.title] + '^', '^')) + ' ' + substring([$Technician_x0020_Profile.title], 0, indexOf([$Technician_x0020_Profile.title], ' ')), ',' '')"

I'm working with the profile title, reversing the name order to "FirstName LastName" without commas.

Any help would be appreciated!

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

Accepted answer
  1. Ling Zhou_MSFT 21,240 Reputation points Microsoft Vendor
    2023-07-31T01:39:08.0766667+00:00

    Hi @mLantz,

    Great to know that and thanks for sharing the update here.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others.". and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    [How do I use a number value field in JSON using "if" condition(s) for SharePoint List formatting a txtContent?]

    Issue Symptom:

    Use if conditions to add an emoji before winners' profile titles. Incorrect addition of emoji before a winners' profile titles.

    Current status:

    You have found out that you need to go into the settings for that view and enable the "Sort" field.

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community members to see the useful information when reading this thread. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated!


1 additional answer

Sort by: Most helpful
  1. mLantz 20 Reputation points
    2023-07-28T20:44:58.1733333+00:00

    Never mind. I found out what was wrong. I needed to go into the settings for that view and enable the "Sort" field. That's hidden in via my advanced formatting.

    My final conditional formatting work perfectly, =if([$Sort] == 1, '🥇', if([$Sort] == 2, '🥈', if([$Sort] == 3, '🥉', ''))) + replace(substring([$Technician_x0020_Profile.title], indexOf([$Technician_x0020_Profile.title], ' ') + 1, indexOf([$Technician_x0020_Profile.title] + '^', '^')) + ' ' + substring([$Technician_x0020_Profile.title], 0, indexOf([$Technician_x0020_Profile.title], ' ')), ',' '').

    I hope this helps someone else that needs to use a number field; just be sure you have it enabled. 😅

    0 comments No comments

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.