ADF does not allow you to reference actions from inside a ForEach loop if those actions are within multiple nested levels of loops. The @activity('Copy account to ADL').Error['message'] expression cannot be used outside of the ForEach activity when the action is nested within it.
Here are some workarounds :
- Use Variables: You can store the error message in a variable within the
ForEachloop and then reference that variable outside of the loop. Here's a potential approach:- Add a Set Variable activity inside the
ForEachloop to capture the error message from theCopy account to ADLactivity. - Use this variable outside of the
ForEachloop instead of referencing the activity directly.
- Add a Set Variable activity inside the
- Flatten the Loop Structure: If possible, try to reduce the nesting of
ForEachactivities. You can have a singleForEachloop and manage the iterations within a single level to allow referencing theCopy account to ADLactivity. - Scope/On-Error Activities: Consider using the built-in failure handling mechanisms like
OnErrororScopeactivities. You can wrap yourCopy account to ADLactivity in aScopeactivity and handle the error within theScope.