In Azure Data Factory is it possible to retrieve the status (Succeeded, Failed etc) of a ForEach activity (that iterated over numerous items). We would like to store the status of ForEach in the OnComplete of ForEach in a stored procedure call. When we try to access activity outputs ForEach activity is not available.
Azure Data Factory Retrieve the status of ForEach Activity.
Foreach activity is just a loop it only iterates the items. It does not give any output because of it we can't get foreach activity in activity output outside of it.
The only work around to your requirement is to set different set variables for On success
and on failure
of foreach activity as below:
We are trying to get the status of the foreach activity (overall).
As we know ForEach activity fails when the inner activity fails for a single time so based on that we can create logic below.
create append variable activity and get the status from the copy activity for each run with expression @activity('Copy data1').output.executionDetails[0].status
After this create a set variable outside of the foreach activity and set the value Failed if Failed is present in activitystatus
array otherwise Succeed with expression @if(contains(variables('activitystatus'),'Failed'),'Failed','Succeed')