What is the best way to determine the length of an array which is a member of a dictionary?
The length(array) or count(array) functions are frequently used to determine the length of an array or list of values. But if the array is a member of a dictionary, these functions always return a length of one.
This test code illustrates the issue:
a!localVariables( local!list: { "A", "B", "C" }, local!emptyList: { }, local!nestedList: { list: { "A", "B", "C" } }, local!emptyNestedList: { list: { } }, { "list" : { list: local!list, length: length(local!list), count: max(a!forEach(local!list, fv!itemCount)) }, "emptyList" : { list: local!emptyList, length: length(local!emptyList), count: max(a!forEach(local!emptyList, fv!itemCount)) }, "nestedList" : { list: local!nestedList.list, length: length(local!nestedList.list), count: max(a!forEach(local!nestedList.list, fv!itemCount)) }, "emptyNestedList" : { list: local!emptyNestedList.list, length: length(local!emptyNestedList.list), count: max(a!forEach(local!emptyNestedList.list, fv!itemCount)) } } )
Test results:
Dictionary
Discussion posts and replies are publicly visible
The nested lists are not strongly typed, you can see this in the expression rule designer that local!nestedList.list is an Any Type (List of Text). To properly cast it I recommend using the cast function or using a!flatten() around you nested list. For example:
length(a!flatten(local!nestedList.list))