Formatting a Person or group type column

This blog demonstrates how you could apply different formatting to a person or group type of column in a SharePoint Online list. With column formatting a last name, first name format is applied.

Inspiration

This question from y2kardell:

I have a SharePoint Person Column with a list of names (first name then last name).
I am wanting to use Power Automate to take the name from that column and copy it to a second list, but instead of the first name then last name – I want to have the last name then first name copied the second list. Is this possible?

Power Users Community thread: Take Sharepoint Person Column and Display Last & First Names.

First Name Last Name

Like suggested in the thread we assume a list has been created with a field of type person or group. The names are shown in a First Name Last Name format. In this blog I will share three other formats via SharePoint Online Column formatting.

In this example I am only using one First Name and one Last Name (with one space character). I am aware that people out there might have double names which will result in multiple space characters. This solution approach has not been tested for those type of names..

personfield_firstnamelastname

First Name

Lets start with retrieving the first name of a person. You could use a indexOf operator to find the first space character. You can use that position of that space character in a substring function. The substring returns the part of the string between the start and end indexes.

firstname_format

1. Add a new Single line of text columm to the list. Call it First Name.

2. Select Column Settings, Format this column

3. Add the json code below to the column and click Save.

Last Name

For the Last Name we want to use a substring again. However, in this instance we want to start directly after the space character. This would be the same formula as in the first name + 1.

For the end index we would need to know the length of the whole string. The length function does not support a string value. Microsoft has shared a string length workaround for this by using an indexOf. Just add a unique character (like ^) at the end of your string and find the position of that character.

lastname_format

1. Add a new Single line of text columm to the list. Call it Last Name.

2. Select Column Settings, Format this column

3. Add the json code below to the column and click Save.

Last Name, First Name

You can put the first name and last name together with for example a comma character. Just use the first name + ‘, ‘ + last name syntax.

lastnamefirstname_format

1. Add a new Single line of text columm to the list. Call it LastNameFirstName.

2. Select Column Settings, Format this column

3. Add the json code below to the column and click Save.

That should be it for the setup.

Happy testing!

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.