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 Lead Developer

    I have tried to replicate your requirement; please have a look at it.

    a!localVariables(
      local!originalList: {
        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!originalList,
        expression: a!localVariables(
          local!currentMap: fv!item,
          local!nullKeys: reject(
            fn!isnull,
            a!forEach(
              items: a!keys(local!currentMap),
              expression: if(
                isnull(index(local!currentMap, fv!item, null)),
                fv!item,
                null
              )
            )
          ),
          remove(local!currentMap, local!nullKeys)
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    I have tried to replicate your requirement; please have a look at it.

    a!localVariables(
      local!originalList: {
        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!originalList,
        expression: a!localVariables(
          local!currentMap: fv!item,
          local!nullKeys: reject(
            fn!isnull,
            a!forEach(
              items: a!keys(local!currentMap),
              expression: if(
                isnull(index(local!currentMap, fv!item, null)),
                fv!item,
                null
              )
            )
          ),
          remove(local!currentMap, local!nullKeys)
        )
      )
    )

Children
No Data