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
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) ) ) ) )
Thanks, It works.
If an answer works, it help to mark it as the Answer so as to help other users refer that in case they are stuck with same issue.
Yes I did thanks for suggestion