Skip to main content

Notifications

Power Automate - General Discussion
Unanswered

cancel/terminate/escape ForEach(ApplyToEach) Loop inside child flow

(0) ShareShare
ReportReport
Posted on by 45

So I'm stuck on a situation where I have a parent and a child flow. Parent flow waits for a child flows response. Child flow responds success when child flow run is completed successfully. However, I have an approval process within the child flow that is inside a ApplyToEach(ForEach) loop, and I need to exit this foreach loop. "Terminate" action cannot be used inside a foreach loop. Hence I tried using "CancelFlowRun" action. This works by cancelling the child flow, but the issue is it sends back no response to the parent flow. Parent flow keeps on retrying to start the child flow. Now I have also turned the Retry Policy to "None". Which means parent flow will not retry to start the child flow. But the issue is the parent flow fails due to the fact child flow did not respond because it was cancelled. And we cannot use Respond to flow option or Response HTTP option from child flow within a ForEach loop, this is not allowed.

 

Is there any suggestion. I do not want to rewrite my entire flow, took a lot of time and effort 😥

Categories:
  • MoshinK786 Profile Picture
    MoshinK786 45 on at
    Re: cancel/terminate/escape ForEach(ApplyToEach) Loop inside child flow

    Hi @DJ_Jamba ,

     

    So now I have ran into an issue where only maximum of 8 nesting condition is allowed. I cannot use IfThenElse condition anymore inside the ApplyToEach. 😥

     

    MoshinK786_0-1716949019978.png

     

  • DJ_Jamba Profile Picture
    DJ_Jamba 2,327 on at
    Re: cancel/terminate/escape ForEach(ApplyToEach) Loop inside child flow

    Hi @MoshinK786 

    Declare a boolean variable at the top of your flow with it's default set to false e.g.

    DJ_Jamba_0-1716908132651.png


    In your Apply to each loop, the first action should be a condition to check that StopLoop is false.
    After each iteration in your Apply to each loop, add another condition that should determine whether you should continue processing the remaining loop items. If it should not continue, set your variable to true. e.g.

    DJ_Jamba_1-1716908723878.png

     

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,567

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard