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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Convert HTML Table in ...
Power Automate
Answered

Convert HTML Table in email body and store values in SQL

(0) ShareShare
ReportReport
Posted on by 128

I've got emails which are in a shared Mailbox. These emails have a HTML table. I want to store these values in a SQL Table.

One solution i found was to clean teh HTML and convert to text using "Html To Text" Action. 

Shravan_0-1703106978549.png

 

Sample data after converting to text:


[A][B][C][D][E][F][G]RowvalueA;RowValueB;RowValueC etcc....

 

Column values are in [], row values are seperated by ";"

 

Maybe store the row values in variables and apply to each??? How would i identify the row values and loop through the sql table. 

 

Any help is much appreciated. Thanks.

Categories:
I have the same question (0)
  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi @Shravan 

     

    You could check my blog that extracts data from html table:

    Extract data from html table in email body - Power Platform Community (microsoft.com)

     

    Ony difference is I have used excel for storing the data from html table in email body, so you could change that part.

     

    I hope this will help you in finalizing the solution 🙂

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

  • grantjenkins Profile Picture
    11,063 Moderator on at

    @Shravan Are you able to show the original email with the Table to get a better idea of what you are working with. I'm assuming your Table will have multiple rows of data, or do they only contain a single row?

  • Shravan Profile Picture
    128 on at

    Shravan_0-1703197175113.png

    Thank You

  • Shravan Profile Picture
    128 on at

    @ManishSolanki 

     

    Hi Manish,

    i did try out your methos but my html is complex, so i used "HTMl to Text" and get values in a string.

     

    My method:

    i was able to clean html and get row values as string delimted by new line.

    sample :

    Rowvalue1

    Rowvalue2

    Rowvalue3

    Rowvalue1

    Rowvalue2

    Rowvalue3

     

    Is there a way to convert these values to array and  "apply to each" and store in appropriate columns in a SP list?

    Colum1 = rowvalue1

    C2 = r2

    c3= r3

    and agian loop through c1,c2,c3 for next set of values.

     

    Any hhelp is much appreciated.

     

    If what i'm doing is wrong way of solutioning this, can i give you my HTMl table code and maybe you could explain using your method?

     

    Cheers,

     

    Shravan

  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi @Shravan 

     

    In the sample data, I could see the values are repeating after every 3 rows so one possibility is to group them using chunk function. Here is an example:

    ManishSolanki_0-1704688788647.png

    chunk(split(outputs('Html_to_text')?['body'],decodeUriComponent('%0A')),3)

    Now, add "Apply to each" to iterate for each row. Each row is an array from which you could extract the columns values using an expression:

    ManishSolanki_1-1704688981959.png

    Expression used to get value of 1st element in each iteration:

    item()[0]

    Similarly, to get values of 2nd & 3rd column, use item()[1] & item()[2]

     

    Output:

    Compose action:

    ManishSolanki_2-1704689252673.png

     

    Apply to each action:

    ManishSolanki_3-1704689276813.png

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

  • Shravan Profile Picture
    128 on at

    @ManishSolanki 

    Hi MAnish,

     

    Thanks a lot for your quick response. I was able to get the values accordingly. But my 'newline' delimeter seems to be causing issues when a single row value is multilined. 

    I think i'll have to go through your initial solution but will need your help in doing so. 

    Please see attached email with the html table in the body. can you please apply this html table to your initial solution where you identify the column and row values based on html tags. It will be of huge help to me. 

     

    Thanks in advance and will always be in your debt. Please check my attachment which has sample data and html code. please let me know if u need more details.

     

    Cheers,

     

    Shravan

  • Verified answer
    ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi @Shravan 

     

    Here is the sample flow based on the input data shared by you.

     

    In this example, I have stored the html code in a compose action:

    ManishSolanki_0-1704859527175.png

    <p> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text/css"> <!-- body {padding:0 2em; font-family:Verdana,sans-serif; color:#444; background:#eee} table {background:#34495E; color:#fff; border-radius:.4em; overflow:hidden; margin:1em 0; min-width:300px} tr {border-top:1px solid #ddd; border-bottom:1px solid #ddd} tr {border-color:#46637f} th, caption, td:before {font-weight:bold!important; letter-spacing:-1px; color:#FFFF00!important; font-weight:bold!important} td:before {font-weight:bold; width:6.5em; display:inline-block} td {display:block; color:#FFFFFF} th, td {text-align:left; margin:4px 6pxem} td:first-child {padding-top:.5em} td:last-child {padding-bottom:.5em} @media (min-width: 480px) { td:before {display:none} th, td {display:table-cell; padding:.25em .5em; padding:4px!important} th:first-child, td:first-child {padding-left:0} th:last-child, td:last-child {padding-right:0} } --> </style> </head> <body> <table><caption>Table I of I which is a daily check</caption><thead><tr><th>[Domain]</th><th>[SQLInstance]</th><th>[evaldate]</th><th>[Database]</th><th>[Section]</th><th>[Details]</th><th>[Next Action]</th></tr></thead><tbody><tr><td>CFDAD</td><td>CFD-MPDB</td><td>2024-01-08T10:47:19</td><td>----</td><td>Failed Job Summary</td><td>Count;JobName;error_message;First failure;Last failure</td><td></td></tr><tr><td>CFDAD</td><td>CFD-MPDB</td><td>2024-01-08T10:47:19</td><td></td><td>Failed Job Summary</td><td>1;Multipick - Replen Create - PUHINUI;The job failed. The Job was invoked by Schedule 301 (replen fullfil PUHINUI). The last step to run was step 1 (replen fullfil PUHINUI).;Jan 8 2024 9:10AM;Jan 8 2024 9:10AM</td><td>Assign to DBA</td></tr><tr><td>CFDAD</td><td>CFD-MPDB</td><td>2024-01-08T10:47:19</td><td></td><td>Failed Job Summary</td><td>3;Multipick - Autorelease;The job failed. The Job was invoked by Schedule 284 (Autorelease). The last step to run was step 1 (Autorelease).;Jan 8 2024 8:25AM;Jan 8 2024 9:50AM</td><td>Assign to DBA</td></tr><tr><td>CFDAD</td><td>CFD-MPDB</td><td>2024-01-08T10:47:19</td><td>----</td><td>Failed Logins</td><td>Failure Count;Failure Text;MinFailureDate;MaxFailureDate</td><td></td></tr><tr><td>CFDAD</td><td>CFD-MPDB</td><td>2024-01-08T10:47:19</td><td>msdb</td><td>Failed Logins</td><td>2;Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. Reason: Could not find a login matching the name provided. [CLIENT: 192.168.9.106];2024-01-03 18:42:56;2024-01-07 18:42:37</td><td>Raise with client</td></tr></tbody></table></body></html></p>

    Next, add another compose action to extract the table from the input html code with the help of an expression. Expression needs to be added in the extraction window as shown below:

    ManishSolanki_1-1704859662213.png

    replace(replace(replace(concat('<table',first(split(last(split(outputs('Compose'),'<table')),'</table>')),'</table>'),'<br>',''),'&nbsp;',''),decodeUriComponent('%0A'),'')

     

    Finally, add "Select" action to create an array of objects which represent rows. Add expression for 'From' parameter and for each map key & value as shown below:

    ManishSolanki_2-1704859859609.png

    range(2, sub(int(xpath(xml(outputs('Compose_2')), 'count(//table//tbody//tr)')), 1))

    Expression used for Map key & value:

    KEY VALUE
    join(xpath(xml(outputs('Compose_2')),'//table//thead//tr[1]//th[1]//text()'),' ') join(xpath(xml(outputs('Compose_2')), concat('//table//tbody//tr[', item(), ']//td[1]//text()')), ' ')
    join(xpath(xml(outputs('Compose_2')),'//table//thead//tr[1]//th[2]//text()'),' ') join(xpath(xml(outputs('Compose_2')), concat('//table//tbody//tr[', item(), ']//td[2]//text()')), ' ')
    join(xpath(xml(outputs('Compose_2')),'//table//thead//tr[1]//th[3]//text()'),' ') join(xpath(xml(outputs('Compose_2')), concat('//table//tbody//tr[', item(), ']//td[3]//text()')), ' ')
    join(xpath(xml(outputs('Compose_2')),'//table//thead//tr[1]//th[4]//text()'),' ') join(xpath(xml(outputs('Compose_2')), concat('//table//tbody//tr[', item(), ']//td[4]//text()')), ' ')
    join(xpath(xml(outputs('Compose_2')),'//table//thead//tr[1]//th[5]//text()'),' ') join(xpath(xml(outputs('Compose_2')), concat('//table//tbody//tr[', item(), ']//td[5]//text()')), ' ')
    join(xpath(xml(outputs('Compose_2')),'//table//thead//tr[1]//th[6]//text()'),' ') join(xpath(xml(outputs('Compose_2')), concat('//table//tbody//tr[', item(), ']//td[6]//text()')), ' ')
    join(xpath(xml(outputs('Compose_2')),'//table//thead//tr[1]//th[7]//text()'),' ') join(xpath(xml(outputs('Compose_2')), concat('//table//tbody//tr[', item(), ']//td[7]//text()')), ' ')

     

    Output:

     

    ManishSolanki_3-1704860199429.png

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

     

  • Shravan Profile Picture
    128 on at

    @ManishSolanki  Thank you so much. I will test it and see how it goes. Just one more question, how do i store these values in a SP list based on column names? I have created a SharePoint blist with column names, the column names dont change, so how do i store these values in a Sharepoint list accordingly?

  • Shravan Profile Picture
    128 on at

    never mind. I was able to figure it out. 

     

    Thanks a lot for your help @ManishSolanki.

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
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard