Hello there,
I've used the index() and property() function for years to pull from CDTs and dictionaries however I've recently run into a problem where both functions are no longer working as expected. Am I crazy here or is there something else going on?
I would expect both of the following statements to return "999" however, I am actually receiving "null" as the output.
fn!index({startYear: 2022}, "YogiBear", "999")
fn!property({startYear: 2022}, "YogiBear", "999")
The screenshot below shows several varieties of the call, along with proof of dictionary format and content, returning null instead of the defaultValue from the index function. I am able to reproduce this in 4 different environments including a cloud setup.
Discussion posts and replies are publicly visible
This is actually documented functionality for the index() function. When the data is a dictionary, the default is ignored and null is returned.
Utilize a!map to obtain better results:
fn!index(a!map(startYear: 2022), "YogiBear", "999")
fn!index:
The type of the default value must be same as that of the elements in the array.
When the data is a dictionary, if the index is not found in the dictionary, the default will be ignored and a null value will be returned. Consider using a map instead of a dictionary.
Hmm.. Right you are Chris - it says so clear as day in the current documentation.
I find it very annoying though because this change was (apparently) introduced in 21.3 and was NOT mentioned in the release notes for 21.3 or any version since.
I can agree on the annoyance, it has caught quite a few people by surprise.
I know the documentation was updated recently to be more thorough, but I can reproduce this same behavior on my 21.1 environment - would have to defer to Appian as far as when/if any related functionality might have changed.
Agreed, along with a specific timeframe around when the change was introduced. Regression testing this is going to be a PITA and (potentially) explains a whole series of "WTF" bugs I've run into over the past several months.
Eg: A similar post about a change in behavior from a year ago is almost certainly associated with the same change. https://community.appian.com/discussions/f/rules/19895/has-the-index-function-changed-recently/77733#77733