Combine values of array by same two columns data

Certified Senior Developer

Hi all

I need one suggestion please let me know if anyone have an idea

Question: I had data in array ex:

a!map{

(id:1,idTwo:1,value:text),

(id:1,idTwo:2,value:exam),

(id:1,idTwo:1,value:yes)

},

I need to combine the value when id and idTwo are same

Expected Output:

{

(id:1,idTwo:1,value:textyes),

(id:1,idTwo:2,value:exam)

}

Thanks In Advance

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Hope this helps:

    a!localVariables(
      local!array: {
        a!map(id: 1, idTwo: 1, value: "text"),
        a!map(id: 1, idTwo: 2, value: "exam"),
        a!map(id: 1, idTwo: 1, value: "yes")
      },
      local!separator: "_",
      local!arrayWithCompositeKey: a!forEach(
        items: local!array,
        expression: a!update(
          fv!item,
          "compositeKey",
          concat(
            fv!item.id,
            local!separator,
            fv!item.idTwo
          )
        )
      ),
      local!uniqueKeys: union(
        local!arrayWithCompositeKey.compositeKey,
        local!arrayWithCompositeKey.compositeKey
      ),
      a!forEach(
        items: local!uniqueKeys,
        expression: a!localVariables(
          local!ids: split(fv!item, local!separator),
          local!values: index(
            local!arrayWithCompositeKey,
            wherecontains(
              fv!item,
              index(local!arrayWithCompositeKey, "compositeKey", {})
            )
          ),
          a!map(
            id: tointeger(local!ids[1]),
            idTwo: tointeger(local!ids[2]),
            value: concat(local!values.value)
          )
        )
      )
    )

Reply Children