cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Seuadr
Helper IV
Helper IV

Big Newbie here - Compose function sub string question

Hello, 

Short time listener, first time caller here.

I recently took the Microsoft power automate course and am working my way through all of the cool stuff that it appears to be able to do.

I am running into an issue where i am not even novice enough to be called a novice programmer and i don't understand how to correctly syntax something in a compose function sub string:

i have a flow that i am converting an email from HTML to text, then i am using a compose function to snag some stuff out of there that i need i've named the stop to convert the subtle name of "Convert" and the compose function has the following substring expression:

substring(body('Convert'),add(indexOf(body('Convert'),'When:'),5),50)
 
this is correctly selecting what i want - in this case a time range and date (for example:  From 6:15 a.m. to 7:15 a.m., on Monday, May 4th)
 
however, selecting a fixed number of characters on the right side isn't working out well as the days/months tend to vary in length and sometimes i'm getting part of the date lopped off and sometimes i'm getting characters from following rows.
 
i am completely lost on how to nest in a dynamic end to this index, since the end characters aren't always the same. (including the fact that these are manually generated and some people include st or th and some people don't at the end of the date)
 
the light at the end of my tunnel is that the emails are formatted from a template, so the format is always something like:
 

Where:

 

When: From 6:15 a.m. to 7:15 a.m., on Monday, May 4

 

What is being done: 

 

i am unsure how to proceed any advice would be fantastic.

 

Thanks,

 

Jared

1 ACCEPTED SOLUTION

Accepted Solutions

@Seuadr 

If your emails are formatted, you can probably use the split() expression.  You'll probably do two splits - the first one will split on When: and the second will split the results of the first on what comes after the text you want.  Then, trim the result.

Here is an example of what I am talking about.   

Take a look at the accepted solution.

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

Scott

View solution in original post

4 REPLIES 4
ScottShearer
Super User
Super User

@Seuadr 

I am having a little trouble understanding your issue (probably my ADD...) but have you tried using the HTML to Text action?

 

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

Scott

Scott,

 

thanks for the quick response - I am probably not doing a great job of explaining.

My flow takes the HTML email and converts the body to text, and then i am using a compose data action to select some of the data i want to insert into an excel table. (convert is the name of the HTML to text convert action)

 

substring(body('Convert'),add(indexOf(body('Convert'),'When:'),5),50) 

 

However, because i am indexing from "When:" and then using a fixed number of characters, sometimes i am getting either the date snipped off or extra characters (because the days and months aren't abbreviated so they vary significantly in length) 

 

for instance - this was pulled out today while i was testing:

 

 From 6:15 a.m. to 7:15 a.m., on Thursday, May 7



Wha

 

I'm trying to figure out how to index the end of the line so that it will end with the date, rather than use a fixed number of characters. I know nothing about this, though, so i am unsure how to do that.

 

does that make more sense?

@Seuadr 

If your emails are formatted, you can probably use the split() expression.  You'll probably do two splits - the first one will split on When: and the second will split the results of the first on what comes after the text you want.  Then, trim the result.

Here is an example of what I am talking about.   

Take a look at the accepted solution.

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

Scott

Scott, that looks pretty promising - i will give that a go!
Thanks for your time and effort,
Jared

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 (3,236)