Skip to main content
sanjuktab2257
June 22, 2025
Question

How to Get Exact Indices of Elements in a List Without Sorting in Appian?

  • June 22, 2025
  • 4 replies
  • 0 views

Hi Everyone,

I'm working with two lists in Appian and need to find the exact indices of elements from one list (local!checkList2) in another list (local!sourceList2) without sorting the data. For example, if local!sourceList2 is {1, 2, 3, 4, 5, 1, 2, 6, 3, 2, 7, 2} and local!checkList2 is {1, 2}, I want to get the indices where these values appear in local!sourceList2 in the original order.

I've tried using wherecontains, but it sorts the data, which I don't want. 

a!localVariables(
  local!sourceList: {3, 4, 5, 3, 7, 4, 7, 6, 5, 4, 3, 9, 2, 2, 3, 2, 2, 3, 3, 2, 4, 2, 2, 2, 2, 3, 2, 2, 3, 2, 4, 2, 3, 2, 2, 2, 4, 3, 2, 2, 2, 2, 2, 3, 2, 4, 5, 4, 2, 5, 6, 3, 4, 4, 7, 3, 4, 6, 4, 4, 2, 3, 2, 2, 2, 4, 2, 2, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 6, 2, 2, 2, 2, 2, 2, 3, 4, 5, 3, 7, 4, 7, 6, 5, 4, 3, 9, 2, 2, 3, 2, 2, 3, 3, 2, 4, 2, 2, 2, 2, 3, 2, 2, 3, 2, 4, 2, 3, 2, 2, 2, 4, 3, 2, 2, 2, 2, 2, 3, 2, 4, 5, 4, 2, 5, 6, 3, 4, 4, 7, 3, 4, 6, 4, 4, 2, 3, 2, 2, 2, 4, 2, 2, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 6, 2, 2, 2, 2, 2, 2, 3, 4, 5, 3, 7, 4, 7, 6, 5, 4, 3, 9, 2, 2, 3, 2, 2, 3, 3, 2, 4, 2, 2, 2, 2, 3, 2, 2, 3, 2, 4, 2, 3, 2, 2, 2, 4, 3, 2, 2, 2, 2, 2, 3, 2, 4, 5, 4, 2, 5, 6, 3, 4, 4, 7, 3, 4, 6, 4, 4, 2, 3, 2, 2, 2, 4, 2, 2, 4, 3, 3, 3, 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, 2, 2, 2, 4, 2, 2, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 6, 2, 2, 2, 2, 2, 2},
  local!checkList: {9, 7, 6, 5, 4, 3, 2},
  local!sourceList2: {1, 2, 3, 4, 5, 1, 2, 6, 3, 2, 7, 2},
  local!checkList2: {1, 2},
  a!map(
    shorterList: wherecontains(local!checkList2, local!sourceList2),
    longerList:  wherecontains(local!checkList, local!sourceList)
  )
 
  
)


I am avoiding loops as it will increase Latency. Is there a way to achieve this with Appian's built in functions.

4 replies

June 23, 2025

Hi, could you please clarify what exact output you're expecting?
For example, are you looking for:

  • The positions (indices) of the matching elements?

  • Just the matching values?

  • Or a grouped result (e.g. indices for each value in checkList2 separately)?

A small example of the desired output would really help. Thanks!

shubhama926776
June 23, 2025

AFAIK Without using any Looping Function  it's not possible to get unsorted list based on index.

June 23, 2025

Without sorting wherecontains() alone won’t preserve the original order of local!checkList2, it returns indices in the order they appear in local!sourcelist2

harshas2775
June 23, 2025

By Definition, wherecontains() will check for values against the array as match comparison. Since you have multiple values to check the source with, the returned indices will be in the order a match is found between array and values. E.g. each element in sourceList is checked against all elements in checkList, if match is found index is returned else it will not be. 

Source being the prime array for comparison , wherecontains() will return indexes in order of the elements in the sourceList. Its not sorting anything, its just returns the indexes as match is found which cannot go out of order unless additional manipulation is done using loops and array functions.