-1

我正在做一些相当简单的事情,并希望我只是错过了一个简单的陈述,我正在尝试进行分组和求和,但似乎无法让 DataWeave 为我完成任务。任何帮助将非常感激!

我有以下 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中必须有一个总和,我还没有找到它。

4

1 回答 1

2

我找到了自己的答案,就这样做-

amtToBill: sum $.u_billed_amount 
于 2015-11-02T21:50:16.000 回答