Appian Community and Appian Academy are being upgraded. From July 24–August 3, the Appian Community will be in read-only mode. During this time, the site will be read-only and user registration will be disabled. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!
The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.
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
Use the expression part of a!forEach to construct a dictionary for each matching item.
expression: if( fv!item.department = "EEE", { id: fv!item.id, name: fv!item.name }, {} )
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 ), {} )
oh right, i keep forgetting where the good places are to use a!map, like here.
Thank you very much Peter