Search code examples
azure-data-factory

ADF lookup to Foreach


I have json input file and using lookup activity and passing to Foreach to get file name list. But I am facing issue in foreach activity and get the file list.

Input Json:

> {
>     "ItemsCount": 2,
>     "FilteredItemsCount": 1,
>     "Value": [
>         {
>             "Sourcetype": "DB",
>             "DB": "test",
>             "Filename": [
>                 "dbo.Emp",
>                 "dbo.Emp1"
>             ]
>         }
>     ] }

Foreach setting:

@activity('Filter2').output.Filename
Error
{
    "errorCode": "InvalidTemplate",
    "message": "The expression 'length(activity('Filter2').output.Filename)' cannot be evaluated because property 'Filename' doesn't exist, available properties are 'ItemsCount, FilteredItemsCount, Value'.",
    "failureType": "UserError",
    "target": "Copy_DB_to_DataLake",
    "details": ""
}

Kindly confirm my foreach setting and let me know if anything needs to add.

Thanks.


Solution

  • Foreach requires an array. To loop over the results of a Filter, you need to reference the 'value' property:

    @activity('Filter2').output.value
    

    Then inside your loop, each iteration can be referenced by using "@item()" as the root object:

    @item().Filename