How to keep only unique items based on the specific key. In this case countryId . Data type is List of Dict

local!test1: {
{
item: "stapler",
name: "Mike",
countryId: 1
},
{
item: "printer",
name: "Larry",
countryId: 2
},
{
item: "laptop",
name: "Mike",
countryId: 1
},
{
item: "glass",
name: "Mike",
countryId: 3
}
},

  Discussion posts and replies are publicly visible

Parents Reply
  • you're trying to replicate the item with the same id and its data. in my application it will change. this solution is not working if add one more entry 

    a!localVariables(
      local!test1: {
        {
          item: "stapler",
          name: "Mike",
          countryId: 1
        },
        {
          item: "printer",
          name: "Larrys",
          countryId: 2
        },
        {
          item: "printer",
          name: "Larry",
          countryId: 2
        },
        {
          item: "laptop",
          name: "Mike",
          countryId: 1
        },
        {
          item: "glass",
          name: "Mike",
          countryId: 3
        }
      },
    
    
      local!res:
      a!forEach(
        items: local!test1,
        expression: {
          item: index(index(local!test1, index(fv!item, "countryId")), "item"),
          name: index(fv!item, "name"),
          countryId: index(fv!item, "countryId"),
        },
    
      ),
    
      union(local!res,local!res)
    
    )

Children
No Data