Hi,
I have this code where if the index points are not returned, it should return the default value. But instead it returns empty data.
How do I make sure that the default value is returned
a!localVariables( local!address1: {{id:1},{id:2}}, local!mdmAddress:{{id:5,name:"abc"},{id:3,name:"pqr"}}, index(local!mdmAddress, wherecontains(local!address1.id,local!mdmAddress.id),"Hello" ) )
Discussion posts and replies are publicly visible
Hi ankitab254
The default value should be the same as that of the array elements as per the documentation.
docs.appian.com/.../fnc_array_index.html
One of the weird behaviours of index(), When you pass empty array as index it returns all values in the array because it treats the index as a list of empty nested field names (text).
But if you pass empty integer array as index it returns empty.
wherecontains() has a return type as integer array even it's empty. so index will return empty.
please check this snippet below.
index({"A","B"},{},{"default"}) /*returns A,B */
index({"A","B"},tointeger({}),{"default"}) /*returns empty */
Hi There,
In such cases, it is always best to add a null check. E.g. Instead of retuning "Hello", please return a null and then in another variable, using an if condition, add a null check to return "hello" in case the indexed property is null or does not exists. Also, please consider creating a custom nullCheck rule that treats null, empty string, and empty list as null.
Thanks everyone for your inputs. i have tried a work around, where i am doing a null check for the index array, but I was just wondering index function itself does the null check and returns the default value, but it's not doing in this case.
Unknown said:using an if condition
And now in 21.2 they've made this even easier since we have a!defaultValue(), such things no longer need to be wrapped in an IF() statement.
Oh yes! How can I forget that But I wonder, does it checks for blank string and blank list too?
I've tested it a bit and it seems like it handles most corner cases well. I may have forgotten some of course.