web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Html-to-text substring...
Power Automate
Unanswered

Html-to-text substring question

(0) ShareShare
ReportReport
Posted on by 16

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')))

 

 

Categories:
I have the same question (0)
  • efialttes Profile Picture
    14,756 on at
    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

  • SemiEvilMonkey Profile Picture
    16 on at
    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

     

  • efialttes Profile Picture
    14,756 on at
    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

  • Verified answer
    v-bacao-msft Profile Picture
    on at
    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,

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 497 Moderator

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 477 Super User 2025 Season 2

#3
chiaraalina Profile Picture

chiaraalina 242

Last 30 days Overall leaderboard