Comparsion between two list of Maps.

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

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Hi  ,

    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", {})
            )
          )
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    Hi  ,

    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", {})
            )
          )
        )
      )
    )

Children
No Data