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

1.3k Views Asked by At

<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.stack.imgur.com/GB3AF.png

email body image : https://i.stack.imgur.com/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 


2

There are 2 best solutions below

3
On BEST ANSWER

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.

4
On

This isn't really a full answer, but it may get you started.

As you can see here,, ALA supports xpath and has an xml parser built it. If you can use that, it will make everything much easier and avoid the need to convert and extract. As far as I can tell, ALA doesn't have an html parser.

The problem is that the html you posted is not a valid xml. For example, the <meta> nodes aren't closed and the whole thing doesn't have a root node. If these are fixed and you have a valid xml, using the templates in that link can easily output what you need.

For example

xpath([your valid xmlstring],'//tr/td[./p//span[./text()="Bot Name "]]/following-sibling::td/p//span[@style="color:black"]/text()')

should output:

Route U2K2 -CR 

Similarly,

xpath([your valid xmlstring],'//tr/td[./p//span[./text()="Bot Overview "]]/following-sibling::td/p//span[@style="color:black"]/text()')

should output:

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

etc. As I said, not a complete answer...