(PS: Following is a simplified example to explain my requirement. the real data is much more huge and complex.)
I have a list of rows which would serve as line items. i need to dynamically group these line items and build a header for each group. if you can follow the structure.
1: input structure output structure
I have implemented the logic but it is only considering alternative rows v.i.z array [0],1,[4],[6]. 1,3,5 etc are missing
here is my logic in data weaver transform message :
%dw 2.0
output application/java
---
flatten(payload map ((item, index) ->
[{
"type":"header",
"name":"",
"code":payload[index].code,
"status":payload[index].status
},
{
"type":"lineitem",
"name":payload[index].name,
"code":"",
"status":""
}]
Idea is to basically split every row into header and line item. and remove duplicate headers in the next step after ordering the line items. All of this is working except alternative rows are missing in the next step(verified by using index to mark rows).
I am also struggling with removal of an array field. For example payload - "status" does not work.
IF anyone can suggest a simpler approach or help me understand why alternative rows are missing, it would be great.