Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

html to text function adding random break lines issue

(0) ShareShare
ReportReport
Posted on by

I am extracting email body then adding the data in a new raw in excel file, using the html to text first, then substring function to extract the needed data.
the issue is that the html to text function is inserting random break lines in the converted texts, the thing that is causing errors in substring function.
does anyone knows why and how the break lines are inserted in html to text function ? and how can i handle it ?

thanks,

 

Capture1.PNGCapture2.PNG

  • Bluehornet Profile Picture
    4 on at
    Re: html to text function adding random break lines issue

    I was having this same issue where as I have a flow that accepts an email w/JSON formated data in HTML, performs html to text, then Parse JSON.  Nothing seemed to work for me to get the line breaks and subsequent \n out of my data.  The only thing that worked is inserting a <br> after each JSON data set within my code (php mailer) that generates the email.  The <br>'s then get stripped out by the html to text and no more random line breaks or \n.

     

    $message = '{';
    $message .= '"Type_of_Request":"'.$requestType. '",<br>';
    $message .= '"Rate":"'.$rate. '",<br>';
    $message .= '"Date_Submitted":"'.$datestamp. '",<br>';
    $message .= '"First_Name":"'.$firstName. '",<br>';
    $message .= '"Last_Name":"'.$lastName. '",<br>';
    $message .= '"Email":"'.$userEmail. '"';
    $message = '}';
  • Bluehornet Profile Picture
    4 on at
    Re: html to text function adding random break lines issue

    I'm having this same issue, but it seems to me that HTML to Text is not adding the \n, its randomly adding a line break, and the then Parse JSON adds the \n for the line break.  How do I remove the \n from the Parse JSON outputs?  I can't use replace() as it expects a string and not an object from the Parse JSON.

    JSON Input from html to text (notice line breaks)

    {"Type_of_Request":"Name

    Change","Rate":"$250.00","Date_Submitted":"2019-04-23 -

    10-45-18-am",

     

    JSON Output

    "Type_of_Request": "Name\nChange",
    "Rate": "$250.00",
    "Date_Submitted": "2019-04-23 -\n10-45-18-am",

     

     

     

  • Verified answer
    Community Power Platform Member Profile Picture
    on at
    Re: html to text function adding random break lines issue

    I found a solution:

    convert the output of the html to text function to array using creatarray(), then converting it back to string using string(), and then removed the /n (break lines) from it using replace(), in this way substing() is not throwing errors.

    hope this would be helpfull.

     

  • Community Power Platform Member Profile Picture
    on at
    Re: html to text function adding random break lines issue

    thanks for your replay @v-yamao-msft , here are the answers to them:

     

    - the error: Unable to process template language expressions in action 'Add_a_row_into_a_table' inputs at line '1' and column '2529': '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. 

    - the function : similar to the context you shared.

    - did not get your question about the email format: it is an outlook email, can you clarifu what details you need. 

    - the break lines instered as the follwoing sample: in the original email, break lines are never like this, and they are changing randomly.  

     

    Lead Contact: test test Organization: gefh Address: dsbsgb vsdvs dfvdf, dvdf
    dfvfd United States Phone Number: (235) 457-4736 Email: vc@dfb.com Program/Event
    Name: gedgvd Program/Event Timeframe: dvfvbzs Website:
    https://clicktime.symantec.com/3PuPQyfz13i5NMBmC5D9vvJ7Vc?u=http%3A%2F%2Fdfg.com
    Donation Type Request: Funding Dollar Amount: 1423 Does your organization
    benefit Blue Diamond's neighborhoods?: Sacramento, CA Focus Areas: Agricultural
    Education Health & Wellness Community Development Briefly describe your
    organization and its mission. How is it administered?: dgbbrth Please attach a
    copy of your most recent annual report.:

     

    hope i could make the issue clearer.

     

     

  • v-yamao-msft Profile Picture
    on at
    Re: html to text function adding random break lines issue

    Hi @Anonymous ,

     

    What’s the error message you’ve got on your side?

     

    Could you share more details on the functions?

     

    What’ the format of the email body?

     

    You mentioned that Html to text action adding random break lines, how is it displayed?

     

    According to your description, I guess that you want to extract contents from the email body. I have made the following test for your reference.

     

    The email is formatted likes below:

    1.PNG

     

    Trigger the flow by When a new email arrives, then the action Html to text.

     

    To get Name, use the following code:

    substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'Name'),5),sub(indexOf(body('Html_to_text'),'Date'),add(indexOf(body('Html_to_text'),'Name'),5)))

     

    Using the following statement to get the Date:

    substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'Date'),5),sub(indexOf(body('Html_to_text'),'Comments'),add(indexOf(body('Html_to_text'),'Date'),5)))

     

    The similar configuration for the Comments:

    substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'Comments'),9),sub(length(body('Html_to_text')),add(indexOf(body('Html_to_text'),'Comments'),9)))

     

    Images for your reference:

    2.PNG3.PNG

     

    Best regards,

    Mabel

     

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!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow