Manipulating array using Get Metadata and If activity

Tarun Sharma 0 Reputation points

@contains(activity('Get Metadata1').output.childItems,'SalesLT.Customer.txt' )

Why If activity expression is resulting in False? With Get Metadata I am trying to get all files in the Source folder. And if  "SalesLT.Customer.txt" exists in the folder, I want to insert data in the Azure sql table.

Can an array element be required to checked with For loop and for each interaction check if a file exists within that ?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,488 questions
{count} votes

1 answer

Sort by: Most helpful
  1. KranthiPakala-MSFT 46,422 Reputation points Microsoft Employee

    Hi @Tarun Sharma ,

    Welcome to Microsoft Q&A forum and thanks for reaching out here.

    Why If activity expression is resulting in False?

    The reason always the IF condition enters false path is because as per your dynamic expression (@contains(activity('Get Metadata1').output.childItems,'SalesLT.Customer.txt' )) , you are passing @activity('Get Metadata1').output.childItems which is an array type to @contains function. But @contains() function expects a string as input argument and then looks for provided substring exits or not. This is the reason why it always enters false path.

    Resolution: In order to convert the array type to string you can use @String() function and it should help convert your childItems from array to a string type.

    To do so please use below dynamic expression and it should help resolve your issue.

    @contains(string(activity('Get Metadata1').output.childItems),'SalesLT.Customer.txt' )

    Hope this helps.

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments