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.
local!checkList2
local!sourceList2
{1, 2, 3, 4, 5, 1, 2, 6, 3, 2, 7, 2}
{1, 2}
I've tried using wherecontains, but it sorts the data, which I don't want.
wherecontains
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, 2, 2, 2, 2, 2, 2, 2,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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.
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, 2, 2, 2, 2, 2, 2, 2, 2, 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, 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) ) )
Discussion posts and replies are publicly visible
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.