JSON column formatting extract first and last name from @me

Copper Contributor

Can we extract other information from @me?  For example, rather than getting the email address, I'd like to only display the First and/or Last names. I tried @me.givenname and others but didn't work. 

 

"elmType": "button",
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "Status": "=if([$Counter] == 1, 'Approved by ' + @me, [$Status])",

 

 

5 Replies

This is the best I can find to extract first and last name, hopefully all email addresses have the same convention. 
Formatting syntax reference | Microsoft Docs

 

replace(substring(@me, 0, indexOf(@me, '@')), '.', ' ')

 

 

@SSantos "@me" will evaluate only to the email address of the current logged in user and you cannot extract display name (first/last name) from this directly like other people fields.

 

For other people fields, you can use below properties (sample data): 

 

 

{
  "id": "122",
  "title": "Kalya Tucker",
  "email": "email address removed for privacy reasons",
  "sip": "email address removed for privacy reasons",
  "picture": "https://contoso.sharepoint.com/kaylat_contoso_com_MThumb.jpg?t=63576928822",
  "department":"Human Resources",
  "jobTitle":"HR Manager"
}

 

 

where "title" returns the display name of people field.

So, to get the display name of current user, you have to use the expression like you are using.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

This code worked brilliantly for me, however there was a slight issue. If the logged in user's email is not already capitalised in the format Firstname.Lastname@... the code won't capitalise the first letters. Is there possibly a work around that would capitalise the letters of a name from the email format firstname.lastname@... ?

@DoraL420 Currently, there is no default operator/function available in SharePoint JSON formatting to auto-capitalize first letter in the word.

 

SharePoint JSON formatting currently only supports toLowerCase() and toUpperCase() to convert string into all lower case and upper case. Also, these operators/functions are only supported in SharePoint Online and not in SharePoint 2019.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@SSantos 

 

There are some companies who's display names for the .title property do not come up as nicely as First Name 'space' Last Name.  My company comes up as Last Name 'comma space' First Name.

{
  "id": "122",
  "title": "Tucker, Kalya",
  "email": "email address removed for privacy reasons",
  "sip": "email address removed for privacy reasons",
  "picture": "https://contoso.sharepoint.com/kaylat_contoso_com_MThumb.jpg?t=63576928822",
  "department":"Human Resources",
  "jobTitle":"HR Manager"
}

 In order to get the first and last names from a single select person column titled 'Engineer' I had to use the 'substring' function along with the 'indexOf' function.  Here's how I got each part of the person's name.

 

First Name: 

 

substring([$Engineer.title], indexOf([$Engineer.title], ',')+2, indexOf([$Engineer.title] + '^', '^'))

 

(This works as long as the person doesn't have the ^ character in their name.  And I've never met anyone with ^ in their name.)

 

Last Name

 

substring([$Engineer.title], 0, indexOf([$Engineer.title], ','))

 

 

Hope this is helpful for someone else.