Skip to main content

Notifications

Community site session details

Community site session details

Session Id : PV2xf/GbelsiBVJeRIjCgc
Power Automate - Building Flows
Unanswered

Extract Email Text and Add to Excel

Like (0) ShareShare
ReportReport
Posted on 5 Jan 2023 21:38:32 by 16

I am trying to extract text strings (entire lines of text) from emails that come in from prospective customers filling out a form. All the entered information is dumped into the body of the email as text. The format of the email is; first line is the header (e.g. 'name') and the line right below it is the information (in this case, the name the user has entered into the form). Then a space, then the next header line (e.g. 'address') and the line that follows is the address the user has entered.

 

I've created a flow that successfully extracts the text and enters it into an (pre-formatted) excel spreadsheet.

 

However, one of the questions is a conditional ('are you located in the United States') and if the user enters 'no', then the form (and subsequently email) adds two lines; 1) the header 'country' and 2) the country the user enters.

 

I can't figure out how to create the conditional expression that will either look for the 'no' and add the two extra lines, or calculate that there are two extra lines and parse the text appropriately so that it ends up in the correct column in the spreadsheet.

 

An added functionality I would like to include is after the conditional lines, there is information on the source page. If I can accurately capture this source page information, it would be very helpful.

 

I've included a couple of screen shots to help demonstrate what I am referring to (note that in order to mask the data, I mocked up the emails. In reality, all the spacing in the emails is the same, with the exception of the conditional question adding two lines and a space.

 

Any help would be appreciated!

  • fscutaro Profile Picture
    16 on 09 Jan 2023 at 13:24:09
    Re: Extract Email Text and Add to Excel

    Amit,

    OK, I was able to replicate the flow. However, I discovered that in some cases, multiple responses are entered and that results in an incorrect extract. See the below:

     

    1 line:

    fscutaro_0-1673270551168.png

     

    2 lines:

    fscutaro_1-1673270570504.png

     

    My thought is to search the field names and have Power Automate select all the text between names (terms), after I’ve converted the email body to text from HTML, instead of returning the line of text.
    So my questions are; 1) Is that a sound approach and 2) what expressions should I use for that action?

     

    Please let me know your thoughts. Thanks.

    Frank

  • Amit_Sharma Profile Picture
    1,569 Super User 2024 Season 1 on 07 Jan 2023 at 08:16:27
    Re: Extract Email Text and Add to Excel

    Hi @fscutaro 

    Please Create a Flow Same as to me After Converting the html text take Output in Compose Action then follow my flowing steps as shown in my below reply.

     

    - If you want to apply condition on mail body to check is empty or not you can use trigger condition for that for now first create your flow as same to me. 

  • fscutaro Profile Picture
    16 on 06 Jan 2023 at 21:34:20
    Re: Extract Email Text and Add to Excel

    Hi Amit,

    Thanks for sending this information. I was unable to get the automation to run properly, however I played around with what you sent and was able to streamline the flow a bit. The issue is that the output into Excel was not what I was looking for.

     

    I've include the new flow below and the emails/output as attachments. Please let me know if you can take a look and let me know what I am doing incorrectly. Thanks.

     

    Frank

     

    Flow:

     

    fscutaro_0-1673040022486.png

    fx = split(outputs('Html_to_text')?['body'], outputs('NewLine'))

     

     

    fscutaro_1-1673040022489.png

    Outputs = SplitIntoLines

     

    fx = length(trim(item()))

     

     

    fscutaro_2-1673040063381.png

     

    First Name

    fx = trim(replace(outputs('SplitIntoLines')?[4],'"',''))

     

    Last Name

    fx = trim(replace(outputs('SplitIntoLines')?[6],'"',''))

     

    Email

    fx = trim(replace(outputs('SplitIntoLines')?[8],'"',''))

     

    Phone

    fx = trim(replace(outputs('SplitIntoLines')?[10],'"',''))

     

    Specialty

    fx = trim(replace(outputs('SplitIntoLines')?[12],'"',''))

     

    Zip

    fx = trim(replace(outputs('SplitIntoLines')?[14],'"',''))

     

    Facility Affiliation

    fx = trim(replace(outputs('SplitIntoLines')?[16],'"',''))

     

    Healthcare Designation

    fx = trim(replace(outputs('SplitIntoLines')?[18],'"',''))

     

    NPI Number

    fx = trim(replace(outputs('SplitIntoLines')?[20],'"',''))

     

    Reasons For Contact

    fx = trim(replace(outputs('SplitIntoLines')?[22],'"',''))

     

    Country US?

    fx = trim(replace(outputs('SplitIntoLines')?[24],'"',''))

     

    Country (other)

    fx = trim(replace(outputs('SplitIntoLines')?[26],'"',''))

     

    Date Received

    fx = formatDateTime(parseDateTime(split(triggerOutputs()?['body/receivedDateTime'], '+')[0]), 'MM/dd/yyyy', 'en-US')

  • Amit_Sharma Profile Picture
    1,569 Super User 2024 Season 1 on 06 Jan 2023 at 14:32:05
    Re: Extract Email Text and Add to Excel

    Hi @fscutaro 

    After Converting your text get in Compose Action.

    Amit_Sharma_0-1673014861632.png

     

    Then Use Another Compose Action In you flow rename to Split and use expression.

    Amit_Sharma_1-1673014917815.png

     

     

    split(outputs('Compose'),',')

     

     

     

    Then Use Add row into table Action.

    Amit_Sharma_2-1673015043622.png

     

    First Name

     

     

    trim(replace(outputs('Split')?[4],'"',''))

     

     

    Last Name

     

     

    trim(replace(outputs('Split')?[6],'"',''))

     

     

    Email

     

     

    trim(replace(outputs('Split')?[8],'"',''))

     

     

    Phone

     

     

    trim(replace(outputs('Split')?[10],'"',''))

     

     

    Specialty

     

     

    trim(replace(outputs('Split')?[12],'"',''))

     

     

    Zip

     

     

    trim(replace(outputs('Split')?[14],'"',''))

     

     

    Facility Affiliation

     

     

    trim(replace(outputs('Split')?[16],'"',''))

     

     

    Healthcare Designation
     

     

     

    trim(replace(outputs('Split')?[18],'"',''))

     

     

    NPI Number
     

     

     

    trim(replace(outputs('Split')?[20],'"',''))

     

     

    Reasons for Contact

     

     

    trim(replace(outputs('Split')?[22],'"',''))

     

     

    Is your organization based within the United States?

     

     

    trim(replace(outputs('Split')?[24],'"',''))

     

     

     

    Output:

    Amit_Sharma_3-1673015479216.png

     

    Complete Flow

    Amit_Sharma_4-1673015608745.png

     

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


    Contact me if you are interested in custom Power Automate development.

  • fscutaro Profile Picture
    16 on 06 Jan 2023 at 14:17:15
    Re: Extract Email Text and Add to Excel

    FYI, the attached is the text output for the alternate condition (someone outside the US). It shows the extra lines in the text output that need to be addressed with the conditional expression.

  • Amit_Sharma Profile Picture
    1,569 Super User 2024 Season 1 on 06 Jan 2023 at 13:50:57
    Re: Extract Email Text and Add to Excel

    Hi @fscutaro 

    Ok, I will create sample for you

  • fscutaro Profile Picture
    16 on 06 Jan 2023 at 13:32:15
    Re: Extract Email Text and Add to Excel

    I do not have "Logo" as the first line of text.

     

    My first line of text is  "A visitor to www.website.com",

  • Amit_Sharma Profile Picture
    1,569 Super User 2024 Season 1 on 06 Jan 2023 at 13:27:31
    Re: Extract Email Text and Add to Excel

    Hi @fscutaro 

    Please confirm this is your text Sample which always get after converting HTML to text.

    Amit_Sharma_0-1673011643956.png

     

     

  • fscutaro Profile Picture
    16 on 06 Jan 2023 at 13:18:41
    Re: Extract Email Text and Add to Excel

    Here it is. Note that I've changed the data to mask the individual's private information. Hopefully that doesn't impact the file. Also note that I had originally deleted the first line (so the actual extract would have an additional line on top). Lastly, this platform does not support .txt files, so I had to copy/past into a .doc file.

  • Amit_Sharma Profile Picture
    1,569 Super User 2024 Season 1 on 06 Jan 2023 at 13:03:35
    Re: Extract Email Text and Add to Excel

    Please send me HTML to text conversion text

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

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,660 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
Loading started