cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RakeeS
New Member

How to remove first line

Hi, All.

i need to remove the first line of message in power automate

 

example:

 

[EXTERNAL] This message comes from an external organization.

test message

to 

test message

 

 

My flow is below,  i need to fetch the body of newly arrived message, but that body has "

[EXTERNAL] This message comes from an external organization" message as first line, want to remove first line and post rest message. 

RakeeS_0-1654580393350.png

 

..............

any suggestion ?

9 REPLIES 9
ashyriverflow
Resolver II
Resolver II

Hi @RakeeS , you can try out the approach below:

ashyriverflow_1-1654589448648.png

1. Convert HTML to plain text to remove all html tags.

2. The tricky part is the compose 4 - it's not empty, it's actually a new line (press Enter). We need to use this trick to capture new line character later on in our expressions. '\n' does not work in flow expressions.

3. Expression in Initialize variable step:

add(indexOf(outputs('Compose_2'),outputs('Compose_4')), 1)

-> This is to find the index of the first new line (end of the first line) and add 1 to have the index of the start of the second line.

4. Expression in Compose 3: 

substring(outputs('Compose_2'),variables('startOfSecondLine'))

-> Get the rest of the body starting from the start of second line.

 

RakeeS
New Member

Hi, tried but , can find body string printing two times  

RakeeS_2-1654598259999.png

 

 

initialize variable : 

add(indexOf(outputs('Compose2'),outputs('Compose')), 1)

 

Compose2

substring(outputs('Compose2'),variables('remove'))

 

 

output:

its working partially.  but getting body in two times. 

RakeeS_0-1654601220887.png

 

 

 

ashyriverflow
Resolver II
Resolver II

Hi @RakeeS , in which step you got two times of the body? can please you elaborate?

RakeeS
New Member

Hi, @ashyriverflow , getting duplicate message at  Html to text field onwards.

RakeeS_0-1654676124566.png

Inputs

<p><html lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta content="ie=edge"></head><body><p><strong><span style="font-weight:bold">[EXTERNAL]</span> </strong>This message comes from an external organization.</p><div><span class="preheader" style="color:transparent; display:none; height:0; max-height:0; max-width:0; opacity:0; overflow:hidden; visibility:hidden; width:0">test message</span> <div class="container">test message<br></div></div></body></html></p>


Outputs

[EXTERNAL] This message comes from an external organization.

test message
test message

 

ashyriverflow
Resolver II
Resolver II

hi @RakeeS , to me, the conversion seems to be correct. There are two "test message" in the body of the email so in the plain text output we see two "test message". How does the actual email body look like?

hi @ashyriverflow 

below is the email body.

 

RakeeS_0-1654681420901.png

 

Shujaath_Khan
Super User
Super User

Hi @RakeeS 

In case if you have plain text content with you can you try the below code

last(split(variables('mailBody'),'comes from an external organization.'))

So here we're splitting by exact text and taking the second part of it.

 

The outcomes 

shujaathkhan_0-1654682151739.png

 

Thanks

If this post helps, please consider Accept it as the solution to help the other members find it. and Thumbsup if you find it useful in otherways

Hi @Shujaath_Khan 

where i need to change ? 

i can remove the first line, but body printing twice. 

Shujaath_Khan
Super User
Super User

hi @RakeeS ,

 

The code snippet you can use in compose action and the above code snippet only removes the first line only. If body is coming twice well that should be another case to look into.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Users online (2,463)