Duccio Borchi
Duccio Borchi

Reputation: 229

Azure Data Factory use result of a Lookup for iterating in a ForEach

I have a Lookup that gives as a result a column with 200 results. Then i need to use each row in another pipeline, using a ForEach. I've tried @activity(Lookup1).output.value but It does not seem to work. Is there a way to do this?

Upvotes: 0

Views: 7466

Answers (1)

Saideep Arikontham
Saideep Arikontham

Reputation: 6114

If you want to use the output of Lookup activity with ForEach loop where both Lookup activity and Foreach activity are present in the same pipeline, then @activity('Lookup1').output.value will work. But if Lookup activity is in one pipeline and you want to pass this result to ForEach activity in another pipeline, you need to follow a different approach.

Look at the following demonstration (Both activity in same pipeline):

  • The following Lookup activity selects 10 rows of a single column in my table.

enter image description here

  • In ForEach activity, I have given the value @activity('Lookup1').output.value for items.

enter image description here

  • Inside foreach I have used script activity to insert values into a table. The pipeline runs successfully and inserts values into my target table.

enter image description here

When Lookup is in one pipeline and for each in another:

  • Let's say lookup_pipeline pipeline has lookup activity (selects 10 rows of a table column) and execute_pipeline pipeline has foreach activity.
  • In the foreach activity, create a parameter called values of object type.

enter image description here

  • Now go back to lookup_pipeline and create an execute pipeline activity. Select invoked pipeline as execute_pipeline. Once you do this, the parameter values appears below and you can specify its value (@activity('Lookup1').output.value) here.

enter image description here

  • Now open the foreach activity in execute_pipeline and give the value for items as @pipeline().parameters.values

enter image description here

  • I used the same script activity inside foreach activity. Now run the lookup_pipeline, it successfully runs and gives the output.

enter image description here

Note:

  • If you want to pass only the row value to another pipeline (pipeline2) but not entire lookup activity output object, follow the approach used in above method.
  • You can use lookup and foreach in same pipeline(pipeline1), create execute pipeline activity inside foreach activity and pass the row value as @item() (another pipeline 'pipeline2' must have parameter of required type to get row value passed from 'pipeline1').

Upvotes: 2

Related Questions