2015-11-02 115 views
-1

我正在做一些相當簡單的事情,希望我只是想念一條簡單的聲明,我正在嘗試做一個小組並完成總結,但似乎無法使DataWeave完成任務我。任何幫助將非常感激!Mule DataWeave Group by And Sum

我有下面的XML

<?xml version="1.0" encoding="UTF-8"?> 
<getRecordsResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<getRecordsResult> 
     <company>0a6979a72ba5020092d4a5a667da15ac</company> 
     <u_billed_amount>504</u_billed_amount> 
</getRecordsResult> 
<getRecordsResult> 
     <company>548839a72ba5020092d4a5a667da15e0</company> 
     <u_billed_amount>29.17</u_billed_amount> 
</getRecordsResult> 
<getRecordsResult> 
     <company>0a6979a72ba5020092d4a5a667da15ac</company> 
     <u_billed_amount>33.75</u_billed_amount> 
</getRecordsResult> 

而且在dataWeave表達如下 -

%dw 1.0 
%output application/xml 
%namespace ns0 http://www.service-now.com/u_incident_task 

--- 
results: {(
    payload.getRecordsResponse.*getRecordsResult groupBy $.company map  { 

    amtToBill: ($.u_billed_amount) 

    } 
)} 

其產生期望的分組,但是我需要總結結算的金額。

<?xml version='1.0' encoding='UTF-8'?> 
<results> 
    <amtToBill> 
     <u_billed_amount>29.17</u_billed_amount> 
    </amtToBill> 
    <amtToBill> 
     <u_billed_amount>504</u_billed_amount> 
     <u_billed_amount>33.75</u_billed_amount> 
    </amtToBill> 
</results> 

我需要的是以下

<?xml version='1.0' encoding='UTF-8'?> 
<results> 
    <amtToBill> 
     <u_billed_amount>29.17</u_billed_amount> 
    </amtToBill> 
    <amtToBill> 
     <u_billed_amount>537.75</u_billed_amount> 
    </amtToBill> 
</results> 

我知道必須有在dataWeave求和,我還沒有找到它。

回答

2

我發現我自己的答案,只是這樣做 -

amtToBill: sum $.u_billed_amount 
+0

當我發現我的答案,當我公司添加的結果就會失控 –