Skip to main content
vishnun0001
July 29, 2025
Solved

displayvalue() Function returning wrong result

  • July 29, 2025
  • 3 replies
  • 0 views

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.

Best answer by harshas2775

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.'

So it is behaving the way it should! The default value will be returned when value is not found in the 'inArray' parameter. Otherwise the replacement array will loop through! 
Hope it helps. 

3 replies

harshas2775
July 29, 2025

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.'

So it is behaving the way it should! The default value will be returned when value is not found in the 'inArray' parameter. Otherwise the replacement array will loop through! 
Hope it helps. 
shubhama926776
July 29, 2025

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.

stefanhelzle0001
July 29, 2025

If this is your exact use case, I suggest to use the index function instead.