Pratik Somaiya
Can you add nested ForEach activity in ADF Pipelines?

The ForEach activity in Azure Data Factory is used to iterate over items specified in the input. Is it possible to have nested ForEach activities in a pipeline?

By Pratik Somaiya in Azure on Jan 25 2024
  • Nandan Hegde
    Feb, 2024 1

    Unfortunately it is not directly possible to have a for each activity within a for each activity in ADF. In order to achieve that one can have another pipeline with the inner for each activity and call the inner for each activity within the outer for each activity by leveraging the execute pipeline activity

    • 1
  • Jayraj Chhaya
    Jan, 2024 29

    Yes, it is possible to have nested ForEach activities in ADF pipelines. The ForEach activity in ADF allows you to iterate over a collection of items specified in the input. This can be useful when you need to perform a set of actions on each item in the collection.

    To create nested ForEach activities, you can simply add a ForEach activity within another ForEach activity. This allows you to iterate over multiple levels of collections.

    Here is an example of how you can use nested ForEach activities in an ADF pipeline:

    1. {
    2. "name": "NestedForEachPipeline",
    3. "properties": {
    4. "activities": [
    5. {
    6. "name": "OuterForEach",
    7. "type": "ForEach",
    8. "foreach": {
    9. "items": {
    10. "value": "@pipeline().parameters.OuterItems",
    11. "type": "Expression"
    12. }
    13. },
    14. "activities": [
    15. {
    16. "name": "InnerForEach",
    17. "type": "ForEach",
    18. "foreach": {
    19. "items": {
    20. "value": "@pipeline().parameters.InnerItems",
    21. "type": "Expression"
    22. }
    23. },
    24. "activities": [
    25. {
    26. "name": "Action",
    27. "type": "WebActivity",
    28. "dependsOn": [],
    29. "linkedServiceName": {
    30. "referenceName": "AzureBlobStorageLinkedService",
    31. "type": "LinkedServiceReference"
    32. },
    33. "typeProperties": {
    34. "url": "https://example.com",
    35. "method": "GET"
    36. }
    37. }
    38. ]
    39. }
    40. ]
    41. }
    42. ],
    43. "parameters": {
    44. "OuterItems": {
    45. "type": "Array",
    46. "defaultValue": [
    47. "item1",
    48. "item2",
    49. "item3"
    50. ]
    51. },
    52. "InnerItems": {
    53. "type": "Array",
    54. "defaultValue": [
    55. "subitem1",
    56. "subitem2",
    57. "subitem3"
    58. ]
    59. }
    60. }
    61. }
    62. }

    The pipeline contains an outer ForEach activity that iterates over the OuterItems array, and within that, there is an inner ForEach activity that iterates over the InnerItems array. Inside the inner ForEach activity, there is a WebActivity that performs a GET request to a URL.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS