Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
smpa01
Super User
Super User

Pushing inner forEach activities to an outer variable

Is there any way to push the output value of forEach activity to an outer variable?

 E.g.

smpa01_0-1721915330852.png

For example,

Lookup is a SQL look up that returns following and Filter activity filters based on filter_action = 'include'

 

 

 

// output value Lookup
{
	"count": 2,
	"value": [
		{
			"id": 1,
			"filter_action": "include"
		},
		{
			"id": 2,
			"filter_action": "include"
		},
		{
			"id": 3,
			"filter_action": "exclude"
		}		
	]
}

//output value Filter
{
	"ItemsCount": 2,
	"FilteredItemsCount": 2,
	"Value": [
		{
			"id": 1,
			"filter_action": "include"
		},
		{
			"id": 2,
			"filter_action": "include"
		}	
	]
}

 

 

I am storing the output of filter in a variable and based on the array in Filter I am doing Copy Activity forEach objects present in Value array of Filter.

 

While the copying is taking place forEach ingestion how can I access the outer Variable to copy the output of Copy Activity in the same variable.

 

Equivalent Javascript code of what I am hoping to achieve in pipeline

 

smpa01_0-1721918622889.png

 

 

Is it doable?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
frithjof_v
Super User
Super User

 

frithjof_v_0-1721989118233.png

If your variable is of type 'Array', then the 'Append variable' activity can be used inside each foreach iteration to dynamically append new items to the array variable.

Append variable activity - Microsoft Fabric | Microsoft Learn

 

Afterwards, the array variable (with the data from the foreach activity) will be accessible for subsequent pipeline activities outside of the foreach activity.

 

 

 

I think the Collection functions are useful for accessing the data from the array variable in subsequent steps:

Expressions and functions - Microsoft Fabric | Microsoft Learn

Also other functions and activities can be useful.

View solution in original post

2 REPLIES 2
frithjof_v
Super User
Super User

 

frithjof_v_0-1721989118233.png

If your variable is of type 'Array', then the 'Append variable' activity can be used inside each foreach iteration to dynamically append new items to the array variable.

Append variable activity - Microsoft Fabric | Microsoft Learn

 

Afterwards, the array variable (with the data from the foreach activity) will be accessible for subsequent pipeline activities outside of the foreach activity.

 

 

 

I think the Collection functions are useful for accessing the data from the array variable in subsequent steps:

Expressions and functions - Microsoft Fabric | Microsoft Learn

Also other functions and activities can be useful.

Anonymous
Not applicable

Hi @smpa01 ,

Currently Data Factory supports Run a Script activity and send an output summary by email.

I think you can create a Data pipeline and then select Script in the Activities.

vyilongmsft_0-1721959352356.png

Then break it down in detail based on the formatting that needs to be changed.

vyilongmsft_1-1721959588742.png

vyilongmsft_2-1721959636922.png

vyilongmsft_3-1721959685114.png

Eventually it would be possible to push the internal forEach activity to an external email as a Script.

vyilongmsft_4-1721959838626.png

 

 

 

 

Best Regards

Yilong Zhou

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

Helpful resources

Announcements
Fabric July 2025 Monthly Update Carousel

Fabric Monthly Update - July 2025

Check out the July 2025 Fabric update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.