Dataweave Mule4条件语句错误
Dataweave Mule4 conditional statement error
如何在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]
}]
%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 末尾还有一个额外的 custom-attributes,您需要将其删除。
如何在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]
}]
%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 末尾还有一个额外的 custom-attributes,您需要将其删除。