迭代数组并为每个元素生成一个新变量
我有一个 JSON 数组存储在一个变量中,如下所示,
{
"Opportunity": {
"QuoteLineItems": {
"QuoteLineItem": {
"ServiceTypeCode": "CC",
"PhaseLevel": "1",
"Quantity": "1",
"UnitPrice": "2,854.50",
"InvoicedSinceLast": "0.00",
"LevelItems": {
"LevelItem": {
"PhaseLevelItemNumber": "R072",
"DocumentNotes": {
"Note": null
}
}
},
"Colonies": {
"ColonyStage": {
"QuoteColonyLineNumber": "1",
"StageItems": {
"StageItem": {
"StageLineProperty": "CHARGE",
"StageQuoteItemNumber": "ICM_033",
"DocumentNotes": {
"Note": null
}
}
}
}
}
}
},
"QuoteLineItem": {
我需要迭代每个 QuoteLineItem 并为每个项目生成一个新的 json 变量,因此我使用 For every 元素,如下所示
内部对于每个我来说有一个转换 Messgae 生成一个新的 json,如下所示
%dw 2.0
output application/json
---
{
"productCode" : //Not sure how to access the ServiceTypeCode on the QuoteLineItem
"axSequenceNumber" : vars.counter,
}
如何获取 foreach 循环内转换消息中每个 QuoteLineItem 的 ServiceTypeCode。我是 Mulesoft 的新手,非常感谢任何帮助
I have a JSON array stored in a variable which looks like below
{
"Opportunity": {
"QuoteLineItems": {
"QuoteLineItem": {
"ServiceTypeCode": "CC",
"PhaseLevel": "1",
"Quantity": "1",
"UnitPrice": "2,854.50",
"InvoicedSinceLast": "0.00",
"LevelItems": {
"LevelItem": {
"PhaseLevelItemNumber": "R072",
"DocumentNotes": {
"Note": null
}
}
},
"Colonies": {
"ColonyStage": {
"QuoteColonyLineNumber": "1",
"StageItems": {
"StageItem": {
"StageLineProperty": "CHARGE",
"StageQuoteItemNumber": "ICM_033",
"DocumentNotes": {
"Note": null
}
}
}
}
}
}
},
"QuoteLineItem": {
I need to iterate through each of the QuoteLineItem and generate a new json variable for each Item so I am using the For each element like below
Inside the For each I am having a transform Messgae to generate a new json like below
%dw 2.0
output application/json
---
{
"productCode" : //Not sure how to access the ServiceTypeCode on the QuoteLineItem
"axSequenceNumber" : vars.counter,
}
How do I get the ServiceTypeCode for each QuoteLineItem in the transform message inside the for each loop. I a new to Mulesoft and any help is greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
quientelineItem是一个对象,而不是数组,因此您不能使用它来迭代。相反,您可以使用 multi-value selector 将所有匹配的钥匙取回数组并将其用于迭代:
在foreach内部,您会收到输入数组的每个元素作为有效载荷:
我不确定通过将其存储到变量中,您不确定您试图准确地实现的目标。您应该考虑单个转换是否可能无法达到相同的结果。
QuoteLineItem is an object, not an array, so you can't use it to iterate. Instead you can use the multi-value selector to retrieve all matching keys as an array and use that to iterate:
Inside the foreach you receive each element of the input array as the payload:
I'm not sure what you are trying to achieve exactly by storing that into a variable. You should consider if a single transform may not achieve the same results.