首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mulesoft Dataweave表达式引发错误

Mulesoft Dataweave表达式引发错误
EN

Stack Overflow用户
提问于 2020-07-11 23:57:10
回答 1查看 153关注 0票数 0

Check image to view mule4 screen我正在使用mule4构建集成流,Dataweave表达式用于数据转换,postman用于测试HTTP调用,我试图从下面的Dataweave中的XML中获取0011x000014VegoAAC,并将其插入到Salesforce记录中,直到我添加了这两行(它们应该从XML中提取0011x000014VegoAAC )

代码语言:javascript
复制
PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute") 
    filter (item) -> (item.@"attribute-id" == "sscAccountid") 

XML

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
    <order-date>2020-07-10T08:57:05.076Z</order-date>
    <current-order-no>00000907</current-order-no>
    <product-lineitems>
        <product-lineitem>
            <net-price>54.17</net-price>
        </product-lineitem>
    </product-lineitems>
    <custom-attributes>
        <custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
        <custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
        <custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
    </custom-attributes>
</order>

完整的Dataweave代码

代码语言:javascript
复制
 %dw 2.0
    output application/java
    ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
    ---
    [{  
        Ascent4Ecomm__Ecomm_Order_ID__c: payload.ns0#order.ns0#"original-order-no",
        Ascent4Ecomm__Ecomm_Order_Name__c: payload.ns0#order.ns0#"original-order-no",
        Ascent4Ecomm__Ecomm_Order_Number__c: payload.ns0#order.ns0#"original-order-no", 
        attributes: {
            "type": "PBSI__PBSI_Sales_Order__c",
            "referenceId": "SO"
        },
        PBSI__Sales_Order_Lines__r: {
            records: payload.ns0#order.ns0#"product-lineitems".*ns0#"product-lineitem" map ( e , empindex ) -> {
                "attributes": {
                    "type": "PBSI__PBSI_Sales_Order_Line__c",
                    "referenceId": e.ns0#"product-id"
                },
                "PBSI__Item__c": e.ns0#"custom-attributes".ns0#"custom-attribute",
                "PBSI__ItemDescription__c": e.ns0#"product-name"
            }
        },
***These two lines throws error:***
        PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
            filter (item) -> (item.@"attribute-id" == "sscAccountid")
    }]

错误

代码语言:javascript
复制
:Invalid status code: 400, response body: [{"message":"Cannot deserialize instance of reference from START_ARRAY value [line:1, column:423]","errorCode":"JSON_PARSER_ERROR"}]

在这两个linesMule4屏幕出现之前,一切都运行正常

我使用postman对该流进行HTTP调用

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-12 01:00:39

这是一个HTTP 400错误。该描述表明某个应用程序正在尝试解析JSON输入。不清楚与您的DataWeave转换的关系,但是它输出的是Java,而不是JSON。您可能需要将输出更改为application/JSON。

更新:根据评论,您需要从PBSI__Customer__c返回带有某个id的单个字符串,这将从问题中的DataWeave表达式返回一个列表,您需要获取第一个元素。您可以使用索引选择器[0]来实现这一点,尽管我不知道是否可以保证有效负载始终只有一个元素。

代码语言:javascript
复制
PBSI__Customer__c: ((payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
        filter (item) -> (item.@"attribute-id" == "sscAccountid")) [0]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62851429

复制
相关文章

相似问题

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