web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Prevent apply to each loop with SharePoint list and Azure DevOps

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello,

 

Forgive me, I know there are solutions on the site for this issue but I have attempted a few of them, but they dont seem to work as I would expect when applying them to my situation...or most likely I am not implmenting them correctly. 

 

The flow, image below, is meant to be working as a ticketing tool / recording tool within Azure dev ops and email communcations.

  1. An Email request comes in
  2. the email subject is checked against a list
    1. if the subject is not found on the list then a new AD work item is created
      1. Then a new entry of with the subject and the AD workitem ID is logged in a Sharepoint list
    2. If the subject is found on the list & it is not flagged as closed then it updates the workitem via the AD workitem ID
      1. the update for this section has been removed. 

 

My problem is that the call to SharePoint "get items" causes a loop and creats a new item for every current entry in the SharePoint list.

So my question is, how do I prevent the "apply to each" from running multiple times?

Thank you in advance!

 

 

FlowLoop.PNG

 

 

I have the same question (0)
  • RezaDorrani Profile Picture
    12,141 on at
    Re: Prevent apply to each loop with SharePoint list and Azure DevOps

    Hi @GoblinKingdom 

     

    Approach 1

    When querying using get items you can use odata queries to filter the results

    https://docs.microsoft.com/en-us/previous-versions/dynamicsnav-2016/hh169248(v=nav.90)

    Next you can check the count of the get items query to see if items are returned based on your condition(filter query)

    You can use the length expression to check the output 

    If length >0 then item found else not found

     

    Approach 2

    Next option would be in your for each loop you can set a variable value only when your condition is true

    then outside of the loop check the variable value

    if yes - then update

    if no - then create

     

    Regards,

    Reza Dorrani

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

  • Pstork1 Profile Picture
    68,271 Most Valuable Professional on at
    Re: Prevent apply to each loop with SharePoint list and Azure DevOps

    You can't really prevent the loop because Get Items will return a collection of items even if there is only one item retrieved.  So you will have to have a loop.  To prevent creation of multiple items you'll need to use the loop to aggregate the data into variables so that you can use those variables to create one item after the loop exits.

  • GoblinKingdom Profile Picture
    Microsoft Employee on at
    Re: Prevent apply to each loop with SharePoint list and Azure DevOps

     @Pstork1 I have seen this solution on other similiar threads, but i cant seem to get it to work properly for mine. Would you mind going into more detail about how to implement your suggestion?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 647 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 350 Moderator

#3
developerAJ Profile Picture

developerAJ 256

Last 30 days Overall leaderboard