Skip to main content
December 4, 2023
Question

Comparsion between two list of Maps.

  • December 4, 2023
  • 2 replies
  • 0 views

Hi Community ,

We have a requirement where we have to compare two lists of map , Both the Map have same values but these map are created from different query statement.
I want those Keys where Values are different.

For Eg :


Map1 : [[id:230,no:0]; [id:223,no:1]; [id:232,no:1]; [id:264,no:1]]
Map 2 :  [[id:230,no:1]; [id:223,no:2]; [id:232,no:1]; [id:264,no:1]]

I need a expression rule which gives result as 230, 223 bcz Map 2 values are different in it.

Many Thanks !

Regards,
ASK

2 replies

December 4, 2023

Hi [mention:2fdbb523a00f4f2ca0160e12dc479059:e9ed411860ed4f2ba0265705b8793d05] ,

Below code is one of the solution for above problem statement.

a!localVariables(
  local!Map1: {
    { id: 230, no: 0 },
    { id: 223, no: 1 },
    { id: 232, no: 1 },
    { id: 264, no: 1 }
  },
  local!Map2: {
    { id: 230, no: 1 },
    { id: 223, no: 2 },
    { id: 232, no: 1 },
    { id: 264, no: 1 }
  },
  a!forEach(
    items: local!Map1,
    expression: reject(
      fn!isnull,
      a!flatten(
        if(
          index(fv!item, "no", {}) = index(
            index(
              local!Map2,
              wherecontains(
                index(fv!item, "id", {}),
                index(local!Map2, "id", {})
              ),
              {}
            ),
            "no",
            {}
          ),
          {},
          index(fv!item, "id", {})
        )
      )
    )
  )
)

annap0005
December 4, 2023

local!diff:symmetricdifference(local!Map1,local!Map2),
union(index(local!diff,"id",{}),index(local!diff,"id",{}))