How to remove keys from the list of map that has null values

Certified Associate Developer

Hi, 

I want to remove the null value keys from the list of the map below. Please let me know how to achieve that:

{a!map(ABC: 6.7, EFG: 15.44, HIJ: 470.888, KLM: "9.8989984", OPQ: null), a!map(ABC: 8.4, EFG: 15.43, HIJ: 470.656, KLM: "9.2342", OPQ: null), a!map(ABC: 7.2, EFG: 15.42, HIJ: 470.554, KLM: "9.234234", OPQ: null), a!map(ABC: 5.6, EFG: 15.42, HIJ: 470.234, KLM: "9.63242", OPQ: null), a!map(ABC: "", EFG: 15.42, HIJ: 470.665, KLM: "9.54343", OPQ: null)}

Regards,

Sowvik

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    This could also work:

    a!localVariables(
      local!data: {
        a!map(
          ABC: 6.7,
          EFG: 15.44,
          HIJ: 470.888,
          KLM: "9.8989984",
          OPQ: null
        ),
        a!map(
          ABC: 8.4,
          EFG: 15.43,
          HIJ: 470.656,
          KLM: "9.2342",
          OPQ: null
        ),
        a!map(
          ABC: 7.2,
          EFG: 15.42,
          HIJ: 470.554,
          KLM: "9.234234",
          OPQ: null
        ),
        a!map(
          ABC: 5.6,
          EFG: 15.42,
          HIJ: 470.234,
          KLM: "9.63242",
          OPQ: null
        ),
        a!map(
          ABC: "",
          EFG: 15.42,
          HIJ: 470.665,
          KLM: "9.54343",
          OPQ: null
        )
      },
      a!forEach(
        items: local!data,
        expression: a!localVariables(
          local!item: fv!item,
          local!keysToRemove: a!forEach(
            items: a!keys(local!item),
            expression: if(
              a!isNullOrEmpty(index(local!item, fv!item, null)),
              fv!item,
              {}
            )
          ),
          remove(local!item, local!keysToRemove)
        )
      )
    )

Reply
  • 0
    Certified Associate Developer

    This could also work:

    a!localVariables(
      local!data: {
        a!map(
          ABC: 6.7,
          EFG: 15.44,
          HIJ: 470.888,
          KLM: "9.8989984",
          OPQ: null
        ),
        a!map(
          ABC: 8.4,
          EFG: 15.43,
          HIJ: 470.656,
          KLM: "9.2342",
          OPQ: null
        ),
        a!map(
          ABC: 7.2,
          EFG: 15.42,
          HIJ: 470.554,
          KLM: "9.234234",
          OPQ: null
        ),
        a!map(
          ABC: 5.6,
          EFG: 15.42,
          HIJ: 470.234,
          KLM: "9.63242",
          OPQ: null
        ),
        a!map(
          ABC: "",
          EFG: 15.42,
          HIJ: 470.665,
          KLM: "9.54343",
          OPQ: null
        )
      },
      a!forEach(
        items: local!data,
        expression: a!localVariables(
          local!item: fv!item,
          local!keysToRemove: a!forEach(
            items: a!keys(local!item),
            expression: if(
              a!isNullOrEmpty(index(local!item, fv!item, null)),
              fv!item,
              {}
            )
          ),
          remove(local!item, local!keysToRemove)
        )
      )
    )

Children
No Data