'How to use If Condition in Data Factory? - Getting always false

I have Lookup, which (Exec) query from database if tables are empty or not. It get result 1 if table are not empty.

I have if condition where I check if value is true.

@equals(activity('Check_Tables_Empty').output.firstrow, '1')

However I get always pipeline directed to False even lookup returns 1.

Check if tables are empty

Lookup Result: "firstRow": { "": 1 }



Solution 1:[1]

You're comparing whether firstRow (an Object) is equal to '1' (a String). This will always return False, because and Object does not equate to a String.

Normally you would refer to the specific property name you wish to compare such as output.firstRow.propertyName. In this case, since your property name is empty string, you could try referring to the ordinal position output.firstRow[0].

UPDATE

@Kenny_I confirmed only property names are valid, so we can't use the index this way.

My first recommendation would be to update the script that generates the Lookup return value to create valid property names.

Assuming that is not possible, you could tackle this problem by converting the firstRow Object to a string, then parsing the string. The following is pseudocode, broken into steps, but should be pretty close:

@string(@activity('Check_Tables_Empty').output.firstrow)

Should result in a String '{ "": 1 }'

Next, remove the {}, split by :, and select the second value [note - I don't remember off the top of my head if the arrays are 0 or 1 based]:

@split(replace(*your_string_above*,'{}',''), ':')[2]

And convert that to int (optional):

@int(*parsed_string*)

Putting it all together, it should look like this:

@int(split(replace(string(activity('Check_Tables_Empty').output.firstrow),'{}',''), ':')[2])

Use this to populate another Variable, then use that Variable in your If Condition.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1