Skip to main content
muhammada5142
January 9, 2026
Solved

Want to get list of ids containing duplicates

  • January 9, 2026
  • 6 replies
  • 0 views

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

Best answer by shubhama926776

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.

6 replies

shubhama926776
January 9, 2026

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.

muhammada5142
January 9, 2026

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?

stefanhelzle0001
January 9, 2026

Appian will always flatten nested lists.

January 9, 2026

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!updatedDictionary: a!update(
    data: cast(a!listType(type!Map), local!list),
    index: "id",
    value: repeat(length(local!list), null)
  ),
  local!uniqueList: union(
    local!updatedDictionary,
    local!updatedDictionary
  ),
  a!forEach(
    items: local!uniqueList,
    expression: index(
      index(local!list, "id", null),
      wherecontains(
        fv!item,
        local!updatedDictionary
      ),
      {}
    )
  )
)