We are currently performing maintenance on Appian Community. As a result, discussions posts and replies are temporarily unavailable. We appreciate your patience.

Need to filter out few elements from an array of dictionary

Let us say I have array of dictionary    {{id:1,name:"Faisal",department:"EEE"},{id:2,name:"Hasan",department:"E&E"},
{id:3,name:"Faridi",department:"E&C"}}

and I want  to return id and name only based on department="EEE"

How can this be achieved using functions?

I have tried the below but not able to get the result and from this query I am able to return only one field.

a!localVariables(

local!employees:{
{{id:1,name:"Faisal",department:"EEE"},{id:2,name:"Hasan",department:"E&E"},
{id:3,name:"Faridi",department:"E&C"}}
},
a!forEach(
items: local!employees,
expression:if(fv!item.department="EEE",fv!item.name,{})
)
)

  Discussion posts and replies are publicly visible

Parents Reply
  • Mike is absolutely correct - that's the right way to do it. But one additional suggestion (if you're on 20.3 or later) is to use the a!map() function instead of reconstructing a dictionary. The map is basically the same as a dictionary except it doesn't break if you try to use dot notation and the field doesn't exist, so I've found that I prevent a lot of annoying bugs by using a map instead of a dictionary!

    Here's an example using Mike's suggested expression:

    expression: if(
      fv!item.department = "EEE", 
      a!map(
        id: fv!item.id,
        name: fv!item.name
      ),
      {}
    )

Children