cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SemiEvilMonkey
Frequent Visitor

Html-to-text substring question

I have a flow that takes an email and coverts using html-to-text. Then I use a series of composes to pull various info from to create a planner task. 

 

So the email is setup pretty easy for this

 

Client: mydata

Project: mydata

Task: mydata

Assigned: mydata

 

The flow works fine most of the time but if I get a Project with a really long name it fails because at on one of the composes later on (oddly not on the Project name part) I get the index is out of range. 

 

So I think its just a misunderstanding on the functions I am using. Here are the 3 composes I use to get the data (ignore the name its looking for in the example below). So what I thought I was doing was in the first 1 choosing the name of the line I want, then on the 2nd one telling it the start of the following line, then in the 3rd selecting the test between those. I thought the number, in the example "7" was for example counting the number of characters in the name "Type:" So if I wanted it for "Type:" I was putting 5 as the number to couldnt the letters in the name type and the colon and grab all text after that.  But if that is the case then I dont understand why when an item is long that it fails. Could someone please help explain what I am not understanding here.? 

 

add(indexOf(body('Html_to_text'),'Type'),7)

indexOf(body('Html_to_text'),'Assigned')

substring(body('Html_to_text'),outputs('FindEmailStart'),sub(outputs('FindEmailEnd'),outputs('FindEmailStart')))

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Html-to-text substring question

 

Hi @SemiEvilMonkey ,

 

Please refer to the methods below to extract the data you need. I used the sample email body you provided to edit the appropriate expression.

Image reference:

144.PNG

Client:

trim(split(split(body('Html_to_text'),'Client:')[1],'Project:')[0])

Project:

trim(split(split(body('Html_to_text'),'Project:')[1],'Year 4 October 2020 to September 2021 PM:')[0])

Task:

trim(split(split(body('Html_to_text'),'Task:')[1],'Assigned to:')[0])

AssignedTo:

trim(split(split(body('Html_to_text'),'Assigned to:')[1],'Start Date:')[0])

You can also refer to the following examples to learn more ways to extract data from the email body. The basic idea is to find the split point, then use the split() function to split the email body, and then extract part of the content.

https://powerusers.microsoft.com/t5/Building-Flows/Extracting-text-from-email/td-p/334919

Extract-text-from-body-of-an-email-and-create-new-rows-in-excel

 

Hope this helps.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Dual Super User
Dual Super User

Re: Html-to-text substring question

Hi
Sorry, I cannot find string 'Type' in the email body example you shared, not sure what your first expression is pointing to. Is it placed just before 'Client'? And, how many times does 'Type' appear in your body?
Can you share an example of 'HTML to text' output?
Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



SemiEvilMonkey
Frequent Visitor

Re: Html-to-text substring question

that was just an example I didnt put in all real data, the question was more of how to handle variable length since on one of them if it get to long the flow fails. 

Real example: 

 

Resource Allocation modified:

 

Client:  Some Client name

Project:  Some Project that can be vary from short to long option Year 4 October 2020 to September 2021

PM:  some, user

Task:  General stuff and more stuff

Assigned to:   some, user

Start Date: 10/01/2020

End Date:  10/31/2020

Hours Booked:  4.00

Allocation Type: Hard - Remote

Assigned Email: someemail@myemail.com

 

Booking Notes:

Bunch of random stuff here

 

some more here 

 

even more here.

 

 

So then I have a bunch of composes to get each part of data I need. If the Project length is long like in this example then it will always fail on allocation type which in my flow is the 3rd setup of composes. 

 

 

Compose - this is the first compose then I do the other 3 for each data part I need
length(body('Html_to_text'))

Compose 1
add(indexOf(body('Html_to_text'),'Allocation Type'),17)

Compse 2
indexOf(body('Html_to_text'),'Assigned Email')

Compose 3
substring(body('Html_to_text'),outputs('FindAllocationTypeStart'),sub(outputs('FindAllocationTypeEnd'),outputs('FindAllocationTypeStart')))

 

This is the error: Unable to process template language expressions in action 'AllocationType' inputs at line '1' and column '30851': 'The template language function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string. Please see https://aka.ms/logicexpressions#substring for usage details.'.

 

The FindAllocationTypeEnd gets a value of -1

 

The html to text returns something that matches close to this: 

 

Resource Allocation modified: Client: Some Client name Project: CSome Project that can be vary from short to long option 
Year 4 October 2020 to September 2021 PM: some, user Task: General stuff and more 
stuff Assigned to: some, user Start Date: 11/01/2020 End
Date: 11/30/2020 Hours Booked: 4.00 Allocation Type: Hard - Remote Assigned
Email: someemail@myemail.com Booking Notes: Bunch of random stuff here
and some more here. Task Notes: then some stuff here with maybe an address

 

Dual Super User
Dual Super User

Re: Html-to-text substring question

Hi again

Let me see if I understood properly:

"Compose 1" output is

outputs('FindAllocationTypeStart')

"Compose 2" output is

outputs('FindAllocationTypeEnd')

 

If so, did you inspect output values taken by both Composes on Failed Flow executions? Do they share a common pattern? My guessing is that whenever 'Allocation Type' field is empty, you do not have 17 characters but 16, and this could be the reason for the error. You can try by using 16 instead and remove the result leading space with trim() function

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Community Support
Community Support

Re: Html-to-text substring question

 

Hi @SemiEvilMonkey ,

 

Please refer to the methods below to extract the data you need. I used the sample email body you provided to edit the appropriate expression.

Image reference:

144.PNG

Client:

trim(split(split(body('Html_to_text'),'Client:')[1],'Project:')[0])

Project:

trim(split(split(body('Html_to_text'),'Project:')[1],'Year 4 October 2020 to September 2021 PM:')[0])

Task:

trim(split(split(body('Html_to_text'),'Task:')[1],'Assigned to:')[0])

AssignedTo:

trim(split(split(body('Html_to_text'),'Assigned to:')[1],'Start Date:')[0])

You can also refer to the following examples to learn more ways to extract data from the email body. The basic idea is to find the split point, then use the split() function to split the email body, and then extract part of the content.

https://powerusers.microsoft.com/t5/Building-Flows/Extracting-text-from-email/td-p/334919

Extract-text-from-body-of-an-email-and-create-new-rows-in-excel

 

Hope this helps.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (6,355)