How can we stop the foreach activity based on some condition in adf without stopping the whole pipeline ?

Amar Agnihotri 891 Reputation points

I am performing foreach activity in adf and inside foreach i am performing if activity as shown -


This is our lookup file being used in lookup activity -


I defined some loop counters in lookup file and these are from 1 to 100. Now foreach activity is running for 100 times. Inside for each i am using if activity as

This is the condition for each activity

If the continuation token will be null then i want to stop that for each activity otherwise it will go to false section and perform some operation. Can anyone suggest where to mention that exit condition to break the foreach activity.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,103 questions
{count} votes

Accepted answer
  1. Suba Balaji 10,931 Reputation points

    Hi @Amar Agnihotri ,

    Thanks for the question and posting it on Microsoft Q&A platform.

    I can think of two options.

    1. You can use fail activity inside true part in the if condition so that the loop breaks and comes out when the Continuationtoken is null
    2. You can make use of an until activity, instead of a foreach. Reference

    Please revert for any further question on the same.


    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Amar Agnihotri 891 Reputation points

    hi @Suba Balaji and @AnnuKumari-MSFT

    The issue is resolved now. Actually i made the below change . I used empty function rather comparing with null and it is working now -


    Thanks to both of you for your support

    2 people found this answer helpful.