Dataweave Mule4条件语句错误

时间:2020-10-28 18:46:17

标签: dataweave mulesoft mule4

如何在Dataweave 2.0中使用IF ELSE条件?我正在尝试围绕有效载荷数据元素之一执行条件,但是执行该条件时会抛出错误。

Unable to resolve reference of method
Unable to resolve reference of attribute

我想念什么吗?

XML>

    <payments>
    <payment>
        <custom-method>
            <method-name>AdyenComponent</method-name>
            <custom-attributes>
                <custom-attribute attribute-id="adyenPaymentMethod">iDEAL</custom-attribute>
            </custom-attributes>
        </custom-method>
        <amount>145.99</amount>
        <processor-id>Adyen_Component</processor-id>
        <transaction-id>851603387831889A</transaction-id>
        <custom-attributes>
            <custom-attribute attribute-id="Adyen_log"></custom-attribute>
            <custom-attribute attribute-id="authCode">Authorised</custom-attribute>
        </custom-attributes>
    </payment>
</payments>

Dataweave代码

    %dw 2.0
    output application/json
    ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
    ---
    [{
Ascent_FPL__Payment_Method__c   :   if ((payload.order.payments.payment.custom-method.custom-attributes.*custom-attribute filter(item) -> (item.@"attribute-id" == "adyenPaymentMethod")) [0] =="iDEAL") "iDEAL" else (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute" filter(item) -> (item.@"attribute-id" == "creditCardType")) [0]
                        
    }]  

                

1 个答案:

答案 0 :(得分:2)

%dw 2.0
output application/json
ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
---
    [{
Ascent_FPL__Payment_Method__c   :   if ((payload.order.payments.payment."custom-method"."custom-attributes".*"custom-attribute" filter(item) -> (item.@"attribute-id" == "adyenPaymentMethod")) [0] =="iDEAL") "iDEAL" else (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute" filter(item) -> (item.@"attribute-id" == "creditCardType")) [0]
                        
    }] 

在xml的末尾,您还需要删除一个额外的自定义属性。