Search code examples
azure-logic-appstext-extractionemail-body

How to find particular text after convert HTML to text in azure logic app?


<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta content="text/html; charset=utf-8"><meta name="Generator" content="Amazon WorkMail v3.1.358.0"></head><body><table class="Table" width="909" style="border-collapse:collapse; width:909px"><tbody><tr><td style="background-color:#d9e1f2; border-bottom:1px solid black; border-left:1px solid black; border-right:1px solid black; border-top:1px solid black; height:19px; padding:0cm 7px 0cm 7px; width:315px"><p align="center" style="text-align:center"><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Type</span></span></span></p></td><td style="background-color:#d9e1f2; border-bottom:1px solid black; border-left:none; border-right:1px solid black; border-top:1px solid black; height:19px; padding:0cm 7px 0cm 7px; width:215px"><p align="center" style="text-align:center"><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Detail</span></span></span></p></td><td style="height:19px; padding:0cm 7px 0cm 7px; width:64px">&nbsp;</td></tr><tr><td style="border-bottom:1px solid black; border-left:1px solid black; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:315px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Bot ID</span></span></span></p></td><td style="border-bottom:1px solid black; border-left:none; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:215px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">4122</span></span></span></p></td><td style="height:19px; padding:0cm 7px 0cm 7px; width:64px">&nbsp;</td></tr><tr><td style="border-bottom:1px solid black; border-left:1px solid black; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:315px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Bot Name </span></span></span></p></td><td style="border-bottom:1px solid black; border-left:none; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:215px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Route U2K2 -CR </span></span></span></p></td><td style="height:19px; padding:0cm 7px 0cm 7px; width:64px">&nbsp;</td></tr><tr><td style="border-bottom:1px solid black; border-left:1px solid black; border-right:1px solid black; border-top:none; height:38px; padding:0cm 7px 0cm 7px; width:315px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Bot Overview </span></span></span></p></td><td style="border-bottom:1px solid black; border-left:none; border-right:1px solid black; border-top:none; height:38px; padding:0cm 7px 0cm 7px; width:215px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">BOT to process all the SR's raised in remedy for Route U2K2. </span></span></span></p></td><td style="height:38px; padding:0cm 7px 0cm 7px; width:64px">&nbsp;</td></tr><tr><td style="border-bottom:1px solid black; border-left:1px solid black; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:315px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Stakeholder/Business approver Name </span></span></span></p></td><td style="border-bottom:1px solid black; border-left:none; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:215px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><u><span style="color:#0563c1"><a href="mailto:[email protected]" style="color:#0563c1; text-decoration:underline">someemail.com</a></span></u></span></span></p></td><td style="height:19px; padding:0cm 7px 0cm 7px; width:64px">&nbsp;</td></tr><tr><td style="border-bottom:1px solid black; border-left:1px solid black; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:315px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Estimated Run Costs</span></span></span></p></td><td style="border-bottom:1px solid black; border-left:none; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:215px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif">&nbsp;</span></span></p></td><td style="height:19px; padding:0cm 7px 0cm 7px; width:64px">&nbsp;</td></tr><tr><td style="border-bottom:1px solid black; border-left:1px solid black; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:315px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif"><span style="color:black">Margin (Euros) - Optional </span></span></span></p></td><td style="border-bottom:1px solid black; border-left:none; border-right:1px solid black; border-top:none; height:19px; padding:0cm 7px 0cm 7px; width:215px"><p><span style="font-size:11pt"><span style="font-family:&quot;Calibri&quot;,sans-serif">&nbsp;</span></span></p></td><td style="height:19px; padding:0cm 7px 0cm 7px; width:64px">&nbsp;</td></tr></tbody></table></body></html>

email body is in html converted to text like below, I need to find the required data and place those data somewhere.

How to split and take particular required text.

The logic app design : https://i.sstatic.net/GB3AF.png

email body image : https://i.sstatic.net/6k89j.png

the data was not in key value pair


Detail

Bot ID

4122

Bot Name 

Route U2K2 -CR 

Bot Overview 

BOT to process all the SR's raised in remedy for Route U2K2. 

Stakeholder/Business approver Name 



Solution

  • After converting html to text, you can use substring('<text>', <startIndex>, <length>) to get the value you want.

    Before you use substring('<text>', <startIndex>, <length>), you need to get <startIndex>and <length> first.

    To get startIndex

    You can use indexOf(variables('var'),'Bot ID') to get the index of Bot ID, then use add(indexOf(variables('var'),'Bot ID'),6) to get the index behind Bot ID.

    To get length

    You can use indexOf(variables('var'),'Bot Name') to get the index of Bot Name, then use sub(indexOf(variables('var'),'Bot Name'),add(indexOf(variables('var'),'Bot ID'),6)) to get the length.

    The expression like this:

    substring(variables('var'),add(indexOf(variables('var'),'Bot ID'),6),sub(indexOf(variables('var'),'Bot Name'),add(indexOf(variables('var'),'Bot ID'),6)))
    

    The design is like this:

    enter image description here

    I did a test:

    enter image description here

    Note

    The text has \n to start a newline, so you need to adjust the value of the startIndex and length according to your own text.