local!test1: { { item: "stapler", name: "Mike", countryId: 1 }, { item: "printer", name: "Larry", countryId: 2 }, { item: "laptop", name: "Mike", countryId: 1 }, { item: "glass", name: "Mike", countryId: 3 } },
Discussion posts and replies are publicly visible
From Appian docs, displayvalue: "Tries to match a value in a given array with a value at the same index in a replacement array and returns either the value at the same index or a default value if the value is not found."
https://docs.appian.com/suite/help/23.3/fnc_conversion_displayvalue.html
So it is like: Iterate on unique countries, find the index of the first item in the list of ALL the countries, and return the full record at that same index.
This is a great function once you understand how it works!
Thank you so much !. I really appreciate it. I will try to play around and familiar with this function.
{ a!localVariables(local!test1: { { item: "stapler", name: "Mike", countryId: 1 }, { item: "printer", name: "Larry", countryId: 2 }, { item: "laptop", name: "Mike", countryId: 1 }, { item: "glass", name: "Mike", countryId: 3 }},local!unique: union(local!test1.countryId,local!test1.countryId),local!res: a!forEach( items: local!unique, expression: index(local!test1,index(wherecontains(tointeger(fv!item),tointeger(local!test1.countryId)),1,null),null)),local!res)
}