SOLVED

JSON code to reverse display name from last name first name to first name last name

Copper Contributor

Hi all. I have a JSON code on a Person column where I am trying to reverse the display name from Last name, First name to First Name Last name however the column is displaying the JSON code rather than executing and returning First Name Last name. Here is my JSON code:

{
"elmType": "div",
"txtContent": "=if(indexOf([$Scheduler.title], ',') != -1, concat(substring([$Scheduler.title], indexOf([$Scheduler.title], ',')+2), ' ', substring([$Scheduler.title], 0, indexOf([$Scheduler.title], ','))), [$Scheduler.title])"
}
 
Can anyone assist please? Unsure if there is a syntax error however SharePoint is accepting the code so it seems correct. 
 
MAVOTRP_0-1708302071870.png

 

2 Replies
best response confirmed by MAVOTRP (Copper Contributor)
Solution

@MAVOTRP If you have fixed format of display names like Doe, John, use JSON like below: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(indexOf([$Scheduler.title], ',') != -1, substring([$Scheduler.title], indexOf([$Scheduler.title], ',')+2,indexOf([$Scheduler.title] + '^^', '^^')) + ' ' + substring([$Scheduler.title], 0, indexOf([$Scheduler.title], ',')), [$Scheduler.title])"
}

 

Where Scheduler is an internal name of your person or group column in SharePoint list in this format. You can get the correct internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

 

Output

ganeshsanap_0-1708320605458.png


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 worked perfectly thanks so much!
1 best response

Accepted Solutions
best response confirmed by MAVOTRP (Copper Contributor)
Solution

@MAVOTRP If you have fixed format of display names like Doe, John, use JSON like below: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(indexOf([$Scheduler.title], ',') != -1, substring([$Scheduler.title], indexOf([$Scheduler.title], ',')+2,indexOf([$Scheduler.title] + '^^', '^^')) + ' ' + substring([$Scheduler.title], 0, indexOf([$Scheduler.title], ',')), [$Scheduler.title])"
}

 

Where Scheduler is an internal name of your person or group column in SharePoint list in this format. You can get the correct internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

 

Output

ganeshsanap_0-1708320605458.png


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.

View solution in original post