Skip to main content
natarajanm0529
October 24, 2023
Solved

how to remove multiple key from this list of dictionary. I did it like this i want some better solution using remove

  • October 24, 2023
  • 8 replies
  • 1 view

a!localVariables(
  local!array: cast(
    97,
    {
      {
        item: "stapler",
        name: "Mike",
        countryId: 1
      },
      {
        item: "printer",
        name: "Larry",
        countryId: 2
      },
      {
        item: "laptop",
        name: "Mike",
        countryId: 1
      },
      {
        item: "glass",
        name: "Mike",
        countryId: 3
      }
    }
  ),
  local!updatedArray: a!forEach(
    items: local!array,
    expression: remove(fv!item,"item")
  ),
  local!finalArray: a!forEach(
    items: local!updatedArray,
    expression: remove(fv!item,"name")
  ),
  local!finalArray
)

Best answer by amirk1581

Try:

a!localVariables(
  local!array: cast(
    97,
    {
      {
        item: "stapler",
        name: "Mike",
        countryId: 1
      },
      {
        item: "printer",
        name: "Larry",
        countryId: 2
      },
      {
        item: "laptop",
        name: "Mike",
        countryId: 1
      },
      {
        item: "glass",
        name: "Mike",
        countryId: 3
      }
    }
  ),
  a!forEach(
    items:local!array,
    expression: reduce(fn!remove,fv!item,{"name","item"})
  )

)

8 replies

amirk1581
amirk1581Answer
October 24, 2023

Try:

a!localVariables(
  local!array: cast(
    97,
    {
      {
        item: "stapler",
        name: "Mike",
        countryId: 1
      },
      {
        item: "printer",
        name: "Larry",
        countryId: 2
      },
      {
        item: "laptop",
        name: "Mike",
        countryId: 1
      },
      {
        item: "glass",
        name: "Mike",
        countryId: 3
      }
    }
  ),
  a!forEach(
    items:local!array,
    expression: reduce(fn!remove,fv!item,{"name","item"})
  )

)

natarajanm0529
October 24, 2023

Thanks Mate !. Works like a charm. One more QQ how remove duplicate dictionary based on key value pair . In this data i want to remove countryId: 1 . it occurs twice.

amirk1581
October 24, 2023

I had an idea that question was coming as I saw the duplicate value. LOL

There is a plugin to do this on the App Market which I haven't personally tried, and it works on CDTs and it may work on data dictionaries:

(+) Appian Community

B
ut you can also try:

a!localVariables(
  local!array: cast(
    97,
    {
      {
        item: "stapler",
        name: "Mike",
        countryId: 1
      },
      {
        item: "printer",
        name: "Larry",
        countryId: 2
      },
      {
        item: "laptop",
        name: "Mike",
        countryId: 1
      },
      {
        item: "glass",
        name: "Mike",
        countryId: 3
      }
    }
  ),
  local!filteredArray:a!forEach(
    items:local!array,
    expression: reduce(fn!remove,fv!item,{"name","item"})
  ),
  union(local!filteredArray,local!filteredArray)

)