question

RyanAbbey-0701 avatar image
0 Votes"
RyanAbbey-0701 asked ShaikMaheer-MSFT edited

Array contains

The below is getting a "Unable to parse expression" error, anyone can tell me what is wrong?

 @if(contains([1,2,3,4,5,6,7], item().PipeRoute), 'PC', 'PC2')

Basically, item().PipeRoute is a number, if it is between 1 and 7, I want the result to be "PC" else "PC2"

azure-data-factory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RyanAbbey-0701 avatar image
0 Votes"
RyanAbbey-0701 answered ShaikMaheer-MSFT edited

It would appear that Data Factory doesn't recognise [] as an array, you have to createArray(1,2,3...)

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hey Ryan,
When I tried creating a parameter/variable and calling it in Set variable activity ; ADF executes properly :

125846-array.png


 @if(contains(pipeline().parameters.Ar, pipeline().parameters.Test), 'PC', 'PC2')




1 Vote 1 ·
array.png (15.9 KiB)

Hi @RyanAbbey-0701 ,

Thank you for posting on Microsoft Q&A Platform.

Could you please mark your above answer as Accepted Answer? Accepted answers helps community as well.

Yes, you are right, expression language directly will not recognize [] as array, we should utilize createArray() function.

There two ways to overcome this problem,
Option 1: As you mentioned use createArray() function.
Option 2: Create one variable of array type and save your array in to that variable. Use that array in your expression as below.
@if(contains(variables('arrayVar'), 1), 'PC', 'PC2')

Here, "arrayVar" is variable to store your array
125914-image.png

1 Vote 1 ·
image.png (60.0 KiB)