Skip to main content
Known Participant
Feb 26, 2023 9:31 PM UTC
Solved

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

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

adityag9712
Inspiring
Feb 27, 2023 3:44 AM UTC

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
)

- Aditya

5 replies

adityag9712
Inspiring
Feb 27, 2023 3:13 AM UTC

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
)

- Aditya
Known Participant
Feb 27, 2023 3:30 AM UTC

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
Inspiring
Feb 27, 2023 3:44 AM UTC

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
)

- Aditya