cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kpreeti1256
Helper II
Helper II

How to avoid unneccessary Apply to Each loop?

Hi Community Members,

 

I am looking for a way that can help me avoid usage of multiple Apply to Each loops in my Flow. I am passing an input from Canvas App to Flow, which is the name. I want to get the items related to that name from my SP list. There is only 1 record that matches the passed name but when I use "Get Items" action and pass the Filter Query. It is returning one record but when I try to use this value, the action moves inside an Apply to Each loop.

 

Since I have to use this record at multiple places, I do not want to have multiple Apply to Each loops operating on a single record. Has anyone faced something like this before? I will be happy to get your inputs.

 

 

Thanks in advance!

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hi @Kpreeti1256 I recently published a blog which lightly covered what you're trying to do.

 

https://blog.mattweston365.com/2019/12/my-big-5-tips-for-power-automate.html

 

Scroll down (or read ;)) down to the section "3. Don't loop unless you really need to"

 

Let me know if you need any further help from this

View solution in original post

yashag2255
Dual Super User II
Dual Super User II

Hey @Kpreeti1256 

 

You can use the First() function or the arrayname[0] to get the first item from the returned list for this one. 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

3 REPLIES 3

Hi @Kpreeti1256 I recently published a blog which lightly covered what you're trying to do.

 

https://blog.mattweston365.com/2019/12/my-big-5-tips-for-power-automate.html

 

Scroll down (or read ;)) down to the section "3. Don't loop unless you really need to"

 

Let me know if you need any further help from this

yashag2255
Dual Super User II
Dual Super User II

Hey @Kpreeti1256 

 

You can use the First() function or the arrayname[0] to get the first item from the returned list for this one. 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Just to get specific on this, as Matt's array is one from a built in function.

 

If you're working with unlabeled Arrays, such as if you were to create an array by splitting a string using the split function in expressions ... then you can just remove the ['value'] part of this.

 

This is basically the second suggestion that @yashag2255 makes below.

-----

 

To map this out for others that might end up here in the future.

  1. Let's say you have this text in Compose:
    one,two,three,four
  2. Using split you create an array variable, called "arrayVAR":
    split(outputs('Compose'), ',')
  3. You also have "Parse_JSON" that runs on the arrayVAR output, based on this output:
    [ "one", "two", "three", "four" ]
  4. Then to get the second value there, "two", you would simply run this expression:
    body('Parse_JSON')?[1]

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (2,224)