我正在尝试从Salesforce&把它变成一个json。这是我的代码:
%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 :(得分:0)
@insaneyogi,您的输入不正确或您的数据编辑不正确。 在输入中,您已在小型中指定了id。但在数据编织中,它在首都提到。
答案 1 :(得分:0)
我认为这里的问题在于您的Lineitem和Price类型元素。它们是内部和元素的集合。在你的数据映射$。将照顾外部物体。但是,我认为像LineItems__r.Price__c这样的映射是不正确的。它应该有适当的索引,可能是LineItems__r.Price__c [0]。请尝试,它应该工作。首先使用单个元素更改输入的价格或行项目并进行测试。
答案 2 :(得分:0)
看起来agreementLineID和netPrice是数组,你需要在更大的外部地图中使用地图运算符遍历它们以获取所有行项目。这应该有用。