Kenny_I
Kenny_I

Reputation: 2513

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 }

Upvotes: 0

Views: 5511

Answers (3)

I think is also more universal check if there is none "firstRow". I set in one of my cases a check against the output.

@contains(string(activity('Check Txn per Shard').output),'firstRow')

Upvotes: 0

flunardelli
flunardelli

Reputation: 46

I don't if you have an idea about which attributes firstRow will return, but you can use contains like @contains(activity('Lookup Activity').output.firstRow,'YourAttribute') or even empty @not(empty(activity('Lookup Activity').output.firstRow)) for a more universal check.

Upvotes: 2

Joel Cochran
Joel Cochran

Reputation: 7768

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.

Upvotes: 1

Related Questions