Appian Community and Appian Academy are being upgraded. As a part of the upgrade, Appian Community is currently in read-only mode, and user registration is disabled until August 3. 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.

How to filter not null data from list of dictionary ?

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"}

{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

Parents
  • Typically you'd conduct a 2-stage process in your expression:

    1. loop through each of the items in your array, examine each and where the 'name' is null, return null, other wise return the whole item. You can do this using a!forEach()
    2. on the result from 1. use fn!reject() to remove all of the values that are now null

    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:

Reply
  • Typically you'd conduct a 2-stage process in your expression:

    1. loop through each of the items in your array, examine each and where the 'name' is null, return null, other wise return the whole item. You can do this using a!forEach()
    2. on the result from 1. use fn!reject() to remove all of the values that are now null

    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:

Children