如何解决Dataweave 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]
}]
解决方法
%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的末尾,您还需要删除一个额外的自定义属性。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。