cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Split First Name and Last Name from a SharePoint Single Line Field

Hello,

 

I have a SharePoint List with a field named 'PM contact', I am trying to split and return 2 different values, one for First Name and the other for Last Name.

 

I tried the expression below, but it doesn't seem to be working

first(split(triggerbody()?['PM_x0020_contact'],' '))
last(split(triggerbody()?['PM_x0020_contact'],' '))
 
alberto1_0-1631573065650.png

Anyone knows of any alternative method or the correct expression I should use here for this purpose?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

If its a single line of text field then your first code should probably have worked.  I suspect its something with the JSON field name you are using.  If you remove what you have in the compose and just insert the contact field from Get Items and then hover over it what does the tooltip say?  That will be what should go where you currently are using triggerbody()?['PM_x0020_contact']



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

View solution in original post

6 REPLIES 6
Pstork1
Dual Super User
Dual Super User

Is the field in the list a person/group column?  Also, since you are doing a Get items to get the list items you'll need to put your compose inside an Apply to each loop and either save the value as a variable for use outside the loop or use it while inside the loop.  For a people column it should be

first(split(triggerbody()?[ 'PM_x0020_contact' ]?['DisplayName'], ' ' ))
last(split(triggerbody()?['PM_x0020_contact']?['DisplayName'],' '))


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

Anonymous
Not applicable

Thank you @Pstork1.

 

The field "PM contact" is a single line of text.

And the error I got was the following:

"Unable to process template language expressions in action 'Compose' inputs at line '1' and column '28258': 'The template language function 'split' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#split for usage details.'."

 

I added an Apply to Each as per below, but I'm still getting a similar error:

 

alberto1_0-1631626332842.png

 

I am not great with expressions, any ideas?

If its a single line of text field then your first code should probably have worked.  I suspect its something with the JSON field name you are using.  If you remove what you have in the compose and just insert the contact field from Get Items and then hover over it what does the tooltip say?  That will be what should go where you currently are using triggerbody()?['PM_x0020_contact']



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

Anonymous
Not applicable

 

@Pstork1 I get 

{
    "inputs""@items('Apply_to_each_4')?['PM_x0020_contact']"

 

alberto1_0-1631627338734.png

So should the expression become as follows instead?

first(split(@items('Apply_to_each_4')?['PM_x0020_contact'],' '))

Anonymous
Not applicable

@Pstork1 I got it to work with this:

first(split(items('Apply_to_each_4')?['PM_x0020_contact'],' '))
 
Thanks!

For a single line of text that would be the right code.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events happening this month - don't miss out!

 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (3,137)