【问题标题】:Dataweave Mule4 conditional statement errorDataweave Mule4条件语句错误
【发布时间】:2020-10-29 05:03:27
【问题描述】:

如何在 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>

数据编织代码

    %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]
                        
    }]  

                

【问题讨论】:

    标签: dataweave mulesoft mule4


    【解决方案1】:
    %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 末尾还有一个额外的自定义属性,您需要将其删除。

    【讨论】:

    • 更改主要是用引号将包含破折号的属性名称括起来,以免与减号操作混淆。
    • 成功了,谢谢!不知道用引号括起来是个问题,谢谢
    猜你喜欢
    • 2022-11-18
    • 1970-01-01
    • 2017-12-15
    • 2020-09-29
    • 2019-08-23
    • 2023-03-24
    • 2022-01-15
    • 2017-03-31
    • 1970-01-01
    相关资源
    最近更新 更多