Want to get list of ids containing duplicates

Certified Associate Developer

Hi All,

Can you guys please help how do I get list of Ids containing duplicates values in list of objects containing duplicate values. The list always has duplicate values.

This is the list

locallist: {   

{ id:12, FacilityName:"New Test1", FacilityTypeId:8,},    

{ id:13, FacilityName:"New Test0", FacilityTypeId:9,},   

{ id:14, FacilityName:"New Test1", FacilityTypeId:8,},   

{ id:15, FacilityName:"New Test0", FacilityTypeId:9,},   

}

what I want to get list of ids containing duplicates. So in this case, id 12, 14 are duplicate having same FacilityName, FacilityTypeId. And id 13, 15 are duplicate having same FacilityName, FacilityTypeId

local!ResultList: {   {  12, 14 }. {13,15}    }

Any help would be appreciated

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    a!localVariables(
      local!list: {
        {id: 12, FacilityName: "New Test1", FacilityTypeId: 8},
        {id: 13, FacilityName: "New Test0", FacilityTypeId: 9},
        {id: 14, FacilityName: "New Test1", FacilityTypeId: 8},
        {id: 15, FacilityName: "New Test0", FacilityTypeId: 9}
      },
    
      local!withKey: a!forEach(
        items: local!list,
        expression: a!map(
          id: fv!item.id,
          key: fv!item.FacilityName & "-" & fv!item.FacilityTypeId
        )
      ),
    
      local!uniqueKeys: union(local!withKey.key, local!withKey.key),
    
      a!forEach(
        items: local!uniqueKeys,
        expression: a!localVariables(
          local!matchingIds: tointeger(local!withKey[wherecontains(fv!item, local!withKey.key)].id),
          if(count(local!matchingIds) > 1, local!matchingIds, {})
        )
      )
    )

    Let me know if this works for you.

  • 0
    Certified Associate Developer
    in reply to Shubham Aware

    Sure, Thank so much giving me the implementation.  The result I got is {12, 14, 13, 15}. Is there a way I can get {  {12, 14},   {13,15}  }. Want to let the user know specifically that {12,14} and {13, 15} are duplicates?

Reply Children