I'm unable to get the key value from Json. Please find the details below xml to Json conversion.
Input XML:
<DeliveryDetails>
<Information>
<InformationLines>
<InformationLine>
<InformationLineId>1001</InformationLineId>
<ProductId>PREBC518</ProductId>
<ProductDescr>Bag </ProductDescr>
<NumberBase>150.00000000</NumberBase>
<UnitBase>BAG</UnitBase>
</InformationLine>
<InformationLine>
<InformationLineId>1001</InformationLineId>
<ProductId>PREBC518</ProductId>
<ProductDescr>Bag delivery</ProductDescr>
<NumberBase>150.00</NumberBase>
<UnitBase>BAG</UnitBase>
</InformationLine>
<InformationLine>
<InformationLineId>1003</InformationLineId>
<ProductId>PREBC518</ProductId>
<ProductDescr>test</ProductDescr>
<NumberBase>70.00</NumberBase>
<UnitBase>BAG</UnitBase>
</InformationLine>
<InformationLine>
<InformationLineId>1005</InformationLineId>
<ProductId>PREBC518</ProductId>
<ProductDescr> dress </ProductDescr>
<NumberBase>80.00</NumberBase>
<UnitBase>BAG</UnitBase>
</InformationLine>
</InformationLines>
</Information>
%dw 2.0
output application/json
var nb = payload.DeliveryDetails.Information.InformationLines.*InformationLine groupBy
($.InformationLineId ) mapObject (value,key) -> {
(key): sum (value.NumberBase)
}
var test = "1001"
---
nb
Above expression gives the below result
{
"1005": "80.00",
"1003": "70.00",
"1001": 300.00
}
Having 2 questions
1) when i directly use ts.'1001'
i can able to get "300.00"
if i use "ts.test"
it is not fetching the value?, ideally in the above test
can be assigned to different value hence im looking for dynamic retrieval.
2) Using the above XML Input on condition based "($.InformationLineId == "1001" ) i only need to get 'sum of BaseNumber'.
I believe it easily achieve by using reduce
function in Mule4 but not sure how to do condition based in reduce
. Needn't required to use the above dataweave logic. I just need to get specific value if
InformationLineId =="1001"
its sum of "BaseNumber"
Please let me know if the question is not clear. Thanks in advance.