cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RichardUchytil
Advocate I
Advocate I

How to loop through an array skipping the first two elements with Power Automate?

I'm parsing an email message.  This message can contain multiple alert messages.  I have found a way to split the html_to_text so I have each alert as a separate array element.  However, the text I am splitting on is also earlier in the body so I end up not needing the first two array elements.  If there is only one alert I need array element 3, if there are three I need elements 3, 4 & 5.  Ultimately the array element data will be inserted into a sql server database.  

 

I'm thinking I need to use an Apply To Each action.  The problem is I don't know how many elements there will be, just that I need to skip the first two.

 

Any ideas how to skip the first two?  Thanks!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RichardUchytil
Advocate I
Advocate I

Found it!  I need to use skip(variables('Array'),2).  

View solution in original post

3 REPLIES 3
RichardUchytil
Advocate I
Advocate I

Found it!  I need to use skip(variables('Array'),2).  

Mira_Ghaly
Dual Super User
Dual Super User

@RichardUchytil 

Please find below the logic you need to do to skip first 2 items in the array.

1. Initialize a count variable outside of your array

Mira_Ghaly_0-1630532084239.png

2. Inside the apply to each 

1. Add a compose data operation as below

add(variables('count'),1)

2. Set the count variable to the output of the compose operation

3. Add a condition if count = 3 then do your logic , on the yes branch, this will skip the first 2 items in the array

Mira_Ghaly_3-1630532699506.png

 

Hope this works for you!

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

I'm sure that works but seems much more complex than what I found.  Then again, maybe what I found won't work all the time or is even correct?

 

  1. I get the email.
  2. Convert the html to text.
  3. Initialize a variable converting the text to an array using split.
  4. In my Apply to each I set the output from previous steps to skip(variable('NumberOfAlerts'),2).  
  5. Then for testing added a send email step where I'm sending the CurrentItem.

That worked for me.  Is that way bad or wrong?  I'm still very new to Power Automate, so could be I'm doing it wrong.

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (4,299)