1

我想BaseChargePerUnit在下一次迭代中访问前一个值元素。下一次迭代中的NewPrice值必须与上一次迭代的PreviousPrices值相同

 %dw 1.0
 %input payload application/xml
 %output application/xml

 ---
using (w=payload.Order.OrderLines.*OrderLine default [], a=payload.*Order.PaymentMethods.*PaymentMethod default [])
 {((payload.*Order default []) map {    
POSLog:{    
Transaction @(CancelFlag:"false"):{ 
   ((w default []) map {    
    LineItem @(EntryMethod:"Keyed"):{
        Associate:{
            CustomerOrderForDelivery:{
            ((w.LineCharges.*LineCharge default []) map {
                RetailPriceModifier @(MethodCode:"AutomaticPromotion",VoidFlag:"false"):{
                    SequenceNumber:$$ + 1,
                    //Amount @(Action:"Subtract"):$.Extn.@BaseChargeAmount,
                    PreviousPrices:sessionVars.abc when $$ == 0 otherwise w[0].Extn.@BaseUnitPrice - $.Extn.@BaseChargePerUnit, // Clarify
                    NewPrice:w[0].Extn.@BaseUnitPrice - $.Extn.@BaseChargePerUnit   
                }
                })
        }}}})}}})}

这是示例输出

    <?xml version='1.0' encoding='UTF-8'?>
<POSLog>
  <Transaction CancelFlag="false">
    <LineItem EntryMethod="Keyed">
      <Associate>
        <CustomerOrderForDelivery>
          <RetailPriceModifier MethodCode="AutomaticPromotion" VoidFlag="false">
            <SequenceNumber>1</SequenceNumber>
            <PreviousPrices>10</PreviousPrices>
            <NewPrice>8</NewPrice>
          </RetailPriceModifier>
          <RetailPriceModifier MethodCode="AutomaticPromotion" VoidFlag="false">
            <SequenceNumber>2</SequenceNumber>
            <PreviousPrices>8</PreviousPrices>
            <NewPrice>7</NewPrice>
          </RetailPriceModifier>
        </CustomerOrderForDelivery>
      </Associate>
    </LineItem>
  </Transaction>
</POSLog>

输入文件是这样的:

    <?xml version="1.0" encoding="UTF-8"?>
<Order AuthorizationExpirationDate="2015-12-11T20:45:34-05:00">
  <OrderLines>
    <OrderLine AllocationDate="2015-12-11T00:00:00-05:00">
      <Extn BaseLineTotal="3230.00" BaseListPrice="223.00" BaseUnitPrice="10" LineTotal="2000.00" POSDepartmentID="0623" />
      <LineCharges>
        <LineCharge ChargeAmount="40.00" ChargeCategory="SystemPromotion">
          <Extn BaseChargeAmount="2" BaseChargePerLine="20.33" BaseChargePerUnit="2"/>
        </LineCharge>
        <LineCharge ChargeAmount="40.00" ChargeCategory="SystemPromotion" ChargeName="ProductDollarOffPromotion">
          <Extn BaseChargeAmount="9.33" BaseChargePerLine="20.33" BaseChargePerUnit="1"/>
        </LineCharge>
      </LineCharges>
    </OrderLine>
  </OrderLines>
</Order>
4

0 回答 0