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.

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.
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.
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.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

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

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (2,232)