Hi all,
The title basically describes it. I'd like to be able to apply filters on a list of maps on their key values.
For example in the code snippet below, to be able to set filter("name","=",bill) or filter("name", "not null").
Similar to a!queryEntity but for a collection of map instead of a Entity
a!localVariables( local!mapCollection: { a!map(name: "bill"), a!map(name: "bob"), a!map(name: "Jim"), a!map(name: null) } )
Also be able to apply operands like and and or if there are multiple key values in the map collection
Discussion posts and replies are publicly visible
a!localVariables( local!mapCollection: { a!map(name: "bill"), a!map(name: "bob"), a!map(name: "Jim"), a!map(name: null) }, local!option1: index( local!mapCollection, wherecontains({ null, "bill" }, local!mapCollection.name), {} ), local!option2: index( local!mapCollection, where( a!forEach( items: local!mapCollection.name, expression: like(fv!item, "*bill*") ) ), {} ), local!option2 )
Yea, that's basically what I did however it's not a great solution. What if you want to and on a few different keys. You would have local!option3 and local!option4 and union them? That's a lot of looping must be a better algorithm for this
Hope this will resolve the above problem
.
a!localVariables( local!mapCollection: { a!map(name: "bill"), a!map(name: "bob"), a!map(name: "Jim"), a!map(name: null) }, local!option1: index( local!mapCollection, wherecontains({ null, "bill" }, local!mapCollection.name), {} ), local!option2: index( local!mapCollection, where( a!forEach( items: local!mapCollection.name, expression: a!localVariables( local!x: like(fv!item, "*bill*"), local!y: like(fv!item, "*ll*"), local!z: like(fv!item, "*ill*"), and(local!x, local!y, local!z) ) ) ), {} ), local!option2 )
I think you misunderstand my requirement but you helped me find the answer nonetheless. Basing myself on your solution
a!localVariables( local!mapCollection: { a!map(name: "bill", phone: "211"), a!map(name: "bob", phone: "311"), a!map(name: "Jim", phone: "411"), a!map(name: null, phone: "511") }, local!filterName: wherecontains({ null, "bill" }, local!mapCollection.name), local!filterPhone: wherecontains({ "911" }, local!mapCollection.phone), local!filterIndexes: and(local!filterName,local!filterPhone), local!solution: index( local!mapCollection, local!filterIndexes, {} ), local!solution )
This is definitely a valid way to do it, but the other approach I often use is to just use a!forEach() and some kind of text function to check to see if it matches or not. For example, you can use the find() function to check if a text string exists in the list. If it doesn't, return an empty list (which then is removed when the list is flattened).
a!localVariables( local!mapCollection: { a!map(name: "bill", phone: "211"), a!map(name: "bob", phone: "311"), a!map(name: "Jim", phone: "411"), a!map(name: null, phone: "511") }, a!flatten( a!forEach( items: local!mapCollection, expression: if( find("b", fv!item)>0, fv!item, {} ) ) ) )