2017-04-12 68 views
-1

我试图将Salesforce的输出&转换为json。这里是我的代码:Mule:Dataweave迭代不起作用

%dw 1.0 
    %output application/json 

    payload map { 
      headerandlines:{ id   : $.Id, 
       agreementLineID  : $.LineItems__r.Id, 
       netPrice   : $.LineItems__r.Price__c, 
       volume    : $.Volume__c, 
       name    : $.Name, 
       StartDate   : $.Start_Date__c, 
       EndDate    : $.End_Date__c, 
       poField    : $.PO_Field__c, 
       ConsoleNumber  : $.Console_Number__c, 
       Term    : $.Term__c, 
       ownerID    : $.OwnerId, 
       Unit    : $.Unit__c, 
       siteNumber   : $.Site_Num__c, 
       customerNumber  : $.Customer_Num__c 
      } 


     } 

输入有效载荷看起来像这样..它是一个对象的集合。不知何故,改造后只有第一个对象被发送&其余的被破坏。

[ 
    { 
"id": "DA0YAAW", 
"LineID": [ 
    "jGEAU", 
    "jBEAU", 
    "j6EAE" 
], 
"Price": [ 
    "50000.0", 
    "12000.0", 
    "45000.0" 
], 
"netPrice": null, 
"volume": null, 
"name": " Test 2.24", 
"StartDate": "2017-02-17", 
"EndDate": "2018-02-17", 
"poField": "123456", 
"ConsoleNumber": "8888888", 
"PaymentTerm": "thirty (30)", 
"ownerID": “abcd”, 
"OperatingUnit": " International Company", 
"siteNumber": null, 
"customerNumber": null 
}, 
{ 
"id": "a37n0000000DAMAAA4", 
"LineID": [ 
    "JunEAE", 
    "JuiEAE", 
    "KdMEAU", 
    "JuYEAU" 
], 
"Price": [ 
    "5000.0", 
    "8000.0", 
    "5000.0", 
    "5000.0" 
], 
"netPrice": null, 
"volume": null, 
"name": " Test 3.6", 
"StartDate": "2017-03-06", 
"EndDate": "2018-03-16", 
"poField": "12345", 
"ConsoleNumber": "123456-", 
"PaymentTerm": "30 NET", 
"ownerID": “dfgh”, 
"OperatingUnit": ", inc.", 
"siteNumber": null, 
"customerNumber": null 
}, 

...。

]

当我(用API测试)我得到多个对象的完整有效载荷调用此代码浏览器。当我从另一个API调用它时,我只有一个1对象表示它没有循环。我可以确认有效载荷有多个对象。在通过此代码循环来提取多个对象方面,是否有任何缺失?我假设'$'符号足够迭代。

+0

有效载荷是什么样的? – Yevgeniy

+0

你好严重加入了输入有效载荷 – insaneyogi

+0

?您的示例中充满了无效字符,并且它不包含数据织物中引用的单个属性。 – Yevgeniy

回答

0

@insaneyogi,您的输入或者不正确,或者您的数据编织不正确。 这里在输入中指定了小号中的id。但在数据编织中,它在大写中提到。

0

我认为这里的问题在于您的Lineitem和价格类型元素。它们是内部和元素的集合。在你的数据映射$中。会照顾外部的物体。但是,我认为像LineItems__r.Price__c这样的映射是不正确的。它应该有适当的索引,可能是LineItems__r.Price__c [0]。请尝试一下,它应该工作。首先用单个元素更改价格或项目和测试的输入。