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:
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:
Next, I tried typing the formula into the expression area:
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'.":
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.
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
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.
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]
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.
Here is the expression that I used:
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:
But when I type in Split, it disappears:
Any assistance would be very welcome. Thanks again.
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.
WarrenBelz
146,771
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional