Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Help to extract the first word of a sentence

Like (0) ShareShare
ReportReport
Posted on 10 Sep 2021 18:23:34 by 66

I would like to extract the first name from a name and surname field. This field is called 'Title' and is being fetched from a SharePoint list. I am using the following guide to help:

https://powerusers.microsoft.com/t5/General-Power-Automate/Return-First-word-in-a-string/td-p/83522

 

However, I am having trouble in extracting the number of characters before the space between the name and surname. Here is what I have tried:

 

vpatel55_0-1631297447974.png

While the flow runs, rather than returning the number of characters between the first name and surname, it simply returns the input expression, including the name itself:

 

vpatel55_1-1631297582175.png

 

Next, I tried typing the formula into the expression area:

 

vpatel55_2-1631297852834.png

 

However this fails with the message: "Unable to process template language expressions in action 'Compose' inputs at line '1' and column '53550': 'The template language function 'indexOf' expects its first parameter to be of type string. The provided value is of type 'Null'.":

 

 

vpatel55_3-1631297929221.png

 

This doesn't make sense because as its clear in the second screenshot, the 'Title' is being retrieved and so cannot be null.

 

Any help would be appreciated. Thanks.

  • rh2150 Profile Picture
    4 on 16 Nov 2022 at 15:26:41
    Re: Help to extract the first word of a sentence

    Hi, maybe this can help in a future somebody struggling with the same situation. You can just create a variable and use this formula:

    first(split('string', 'separator'))

     

    In the most cases when handling names the separator will be an space ' ' and if you add the first function it will give as output the first word in the string.

     

    Hope it helps

  • vpatel55 Profile Picture
    66 on 11 Sep 2021 at 11:06:39
    Re: Help to extract the first word of a sentence

    Hi @tom_riha thanks, that works! Super user indeed! I will certainly need to see how this works - it was much more complex than I had anticipated. Many thanks and much appreciated.

  • Verified answer
    tom_riha Profile Picture
    10,085 Most Valuable Professional on 11 Sep 2021 at 10:21:08
    Re: Help to extract the first word of a sentence

    Hello @vpatel55 ,

    try to address the title by using outputs(...) instead of body(...).

     

    split(outputs('Get_items')?[Title],' ')[0]

    update:

    since it's using output from 'Get items', it'll always return an array. You should loop through the output and then, inside the apply to each, do the split.

    split(item()?['Title'],' ')[0]

    image.png

     

  • vpatel55 Profile Picture
    66 on 11 Sep 2021 at 08:18:21
    Re: Help to extract the first word of a sentence

    HI @tom_riha thank you for your response. Unfortunately I'm still getting a variation of the same error however, "'The template language function 'split' expects its first parameter to be of type string. The provided value is of type 'Null'. "

     

    However, we can clearly see that 'Title' was not null.

     

    vpatel55_1-1631347673186.png

    Here is the expression that I used:

     

    vpatel55_0-1631347524496.png

     

    I'm not sure if its relevant, but when I start typing the 'split' expression, 'Title' (and almost most other fields) disappear from the dynamic content list. I only achieved the above by manually typing in 'Title'. Perhaps it is not shown because its not available to use, and is returning 'Null' because it can't see it?

     

    This is what I mean, 'Title' is at first available as a dynamic content expression:

    vpatel55_2-1631348094710.png

     

    But when I type in Split, it disappears:

    vpatel55_3-1631348220009.png

     

    Any assistance would be very welcome. Thanks again.

     

  • tom_riha Profile Picture
    10,085 Most Valuable Professional on 10 Sep 2021 at 20:12:11
    Re: Help to extract the first word of a sentence

    Hello @vpatel55 ,

    In your situation I think the split(...) expression would be better, just split(...) the title by the ' ' character and take the first item from that split

    split([TitleDynamicContent],' ')[0]
    
    Note: replace [TitleDynamicContent] with the dynamic content; enter the whole split(...) as an expression.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,771 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard