Hi All,
Please help in understanding or explaining the working of the following code.
displayvalue( 5, { 1, 2, 3, 4, 5 }, { "A", "B", "C", "D" }, "Z")
In the above sample code, based on it's behavior, ideally, the result should be the default value ("Z" in this case as there is no item in 5th index of 2nd array). But the result I'm getting is "A", the 1st index from the array.
Version I'm using is Appian 24.4
Please refer the screenshot attached.
Discussion posts and replies are publicly visible
As per the documentation,
'If the length of the replacement array is shorter than the inArray array, the replacement array will be repeatedly extended until it is the same length as the longer inArray array.'
The displayvalue() function loops the replacement array when it's shorter. Since your replacement array {"A","B","C","D"} has only 4 items but you're looking for position 5, it wraps around to position 1 and returns "A". The default value "Z" is only used when the search value doesn't exist in the input array at all (like searching for 6 instead of 5). This is expected behavior.
If this is your exact use case, I suggest to use the index function instead.