I had written some logic that queried a record (expecting, and getting a single record, by passing a unique filter value)
The query actually could return multiple records, so returns a List of the relevant cdt
Then I tested a boolean field in that record is true or false, and returns one of two lists of items, for example something like this:
if ( index(my_cdt, "booleanField",false), list_one, list_other )
My list was being returned but only with the first item in it!
The issue is that the query returns a list of records, so the if statement parameter 1 is on a list type.
An example of the logic I was actually executing was therefore:
if( {true}, {1,2,3}, {4,5,6} )
This actually returns {1}, not {1,2,3}
if( true, {1,2,3} {4,5,6} )
will return {1,2,3} as expected.
Further example to show what's actually happening:
if( {true,false,true}, {1,2,3}, {4,5,6} )
This returns {1,5,3} !!
An easy mistake to make, so hopefully some one will read this and not fall into the trap I did.
Discussion posts and replies are publicly visible
Yes, this is the usual behavior of the if() function in Appian. The way out is to use and() & or() functions in the condition parameter to either check or all or any.
I have talked about this in my blog post here (Point 8) - appianspace.com/.../
Thanks Harshit - nice blog post! I had come across some of these before, but learnt some new ones too.
Was doing some further playing and this is an interesting one - purely academic of course, but might interest you.
if( {true,false,true,false,false}, {1,2,3}, {4,5} )
why does it return: {1,4,2,5,4} ?
The only explanation that comes to my mind after seeing your first example is...
It has created two arrays internally. One for true and one for false. Now it is just getting you the element on the same index from the relevant blocks. If the list count isn't the same, then Appian is circling back to the first index when it runs of out index. Hence 3rd false gives you 4 again.