Skip to main content
January 27, 2022
Solved

index() and property() function failure

  • January 27, 2022
  • 4 replies
  • 1 view

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.

Best answer by csteward

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:

Usage considerations

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.

4 replies

csteward
cstewardAnswer
January 27, 2022

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:

Usage considerations

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.

jphehAuthor
January 27, 2022

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. 

csteward
January 27, 2022

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.