首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dataweave Mule4条件语句错误

Dataweave Mule4条件语句错误
EN

Stack Overflow用户
提问于 2020-10-29 02:46:17
回答 1查看 242关注 0票数 1

如何在Dataweave 2.0中使用IF ELSE条件?我试图围绕其中一个Payload数据元素执行一个条件,但在执行它时抛出了错误。

代码语言:javascript
复制
Unable to resolve reference of method
Unable to resolve reference of attribute

我是不是遗漏了什么?

XML >

代码语言:javascript
复制
    <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代码

代码语言:javascript
复制
    %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]
                        
    }]  
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-29 02:53:45

代码语言:javascript
复制
%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末尾还有一个额外的自定义属性,需要将其删除。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64579430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档