Hi Team,
I need help.
I have a list of dictionary like
{
{name: "Aish", category: "A"}
{name: "Jenny", category: "A"}
{name: "", category: "C"}
{name: "", category: "E"}
}
Now I want to filter out only that/those dictionary which has name value not null.
Like I want values to return only with name filled, empty rows I don't want.
In the example above it should return only first 2 rows as the name is filled there.
can you suggest anything?
Discussion posts and replies are publicly visible
Typically you'd conduct a 2-stage process in your expression:
Here's the full code:
a!localVariables( local!myArray: { { name: "Aish", category: "A" }, { name: "Jenny", category: "A" }, { name: "", category: "C" }, { name: "", category: "E" }, { name: "", category: "E" } }, fn!reject( fn!isnull, a!forEach( items: local!myArray, expression: if(fv!item.name = "", null, fv!item) ) ) )
...and the result is:
Thanks a lot
Since I loathe the the old looping functions with a fiery passion these days, I would recommend just utilizing a!forEach() for the heavy lifting here. The trick is, have it return an empty set instead of NULL, which in normal circumstances will not be returned as a member of the resulting array. The one corner case is, for some quirky reason if all items are filtered out, then the result ends up returning a list of empty sets equal in length to the original list, but a!flatten takes care of this handily.
a!localVariables( local!myArray: { { name: "Aish", category: "A" }, { name: "Jenny", category: "A" }, { name: "", category: "C" }, { name: "", category: "E" }, { name: "", category: "E" } }, a!flatten( /* (a!flatten only becomes necessary when the filter would cause zero results to be returned) */ a!forEach( items: local!myArray, expression: if( isnull(fv!item.name), {}, fv!item ) ) ) /*fn!reject(*/ /*fn!isnull,*/ /*a!forEach(*/ /*items: local!myArray,*/ /*expression: if(fv!item.name = "", null, fv!item)*/ /*)*/ /*)*/ )
Great! Thank you for your answer!