Embedding Copy Activity Outputs in Array for Iteration in Azure Data Factory's ForEach Loop

Brianna C 120 Reputation points
2024-01-31T03:01:12.03+00:00

Can the output of a copy activity in Azure Data Factory be embedded in an array for subsequent iteration in a ForEach loop? The aim is to create an array with the outputs of multiple copy activities and then access their properties using dot notation (e.g., item().rowsRead) within the ForEach loop for validation purposes. The provided image details the code.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. Smaran Thoomu 24,110 Reputation points Microsoft External Staff Moderator
    2024-01-31T12:20:41.43+00:00

    Hi @Anonymous

    Welcome to Microsoft Q&A platform and thanks for posting your question.

    It's possible to include the results of a copy activity in Azure Data Factory in an array. I've conducted a test to store the output of two copy activities in an array. We'll need to concatenate a string type and then convert it to a JSON type.

    User's image- We can define a variable of the array type called CopyInfo to store the output. Another variable, JsonArray, is used to view the test result in debug mode.

    enter image description here

    • In the Append Variable1 activity, I utilize @json(concat('{"activityName":"Copy1","activityObject":', activity('Copy data1').output, '}')) to store the output of the Copy data1 activity and convert it from a String type to a Json type.

    enter image description here

    • In the Append Variable2 activity, I utilize @json(concat('{"activityName":"Copy2","activityObject":',activity('Copy data2').output,'}')) to store the output of the Copy data2 activity and transform it from a String type to a Json type.

    enter image description here

    • After that, I set the value of the variable CopyInfo to the variable JsonArray.

    enter image description here

    • In the end, we can see the json array like:
    "name": "JsonArray",
    "value": [
        {
            "activityName": "Copy1",
            "activityObject": {
                "dataRead": 643,
                "dataWritten": 643,
                "filesRead": 1,
                "filesWritten": 1,
                ...
        },
        {
            "activityName": "Copy2",
            "activityObject": {
                "dataRead": 643,
                "dataWritten": 643,
                "filesRead": 1,
                "filesWritten": 1,
                ...
                }
        }
    ]
    
    
    

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.