Skip to main content
February 26, 2023
Solved

Creating an expression rule equivalent to a!queryEntity() but for a list of a!map()

  • February 26, 2023
  • 5 replies
  • 0 views

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

Best answer by adityag9712

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
)

5 replies

adityag9712
February 27, 2023

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
)

February 27, 2023

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

adityag9712
February 27, 2023

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
)