
Questions: 23,751 //
Answers: 52,349 //
Contributing Members: 18,020
I have 3 inputs a = [{"SalesforceId":"02i2C000002PRMpQAO", "ExternalId":"10000502"}, {"SalesforceId":"02i2C000002PRMqQAO", "ExternalId":"10000501"}]
, b = [ { "Result": { "errors": "", "id": "02i2C000002PRMpQAO", "success": "true", "created": "true" } }, { "Result": { "errors": "", "id": "02i2C000002PRMqQAO", "success": "true", "created": "false" } } ]
, c = [{ "name": "GMC", "subscriptionId": "10000501", } ,{ "name": "BUIC", "subscriptionId": "10000502", }]
where c.subscriptionId = a.ExternalId and b.id = a.SalesforceId required output -
output -
output -
[
{
"success": "true",
"created": "true"
"JSON": {
"name": "BUIC",
"subscriptionId": "10000502",
}
},
{
"success": "true",
"created": "false"
"JSON": {
"name": "GMC",
"subscriptionId": "10000501",
}
}
]
How do I achieve this in dataweave or mule in general ?
Sep 07, 2018 at 03:14 PM, vijaykumar63 answered with:
I got the result by using function for 3rd json - %dw 1.0 %output application/json %function grab(subscriptionId){ (c[?($.subscriptionId == subscriptionId)]) }
%var a = [{"SalesforceId":"02i2C000002PRMpQAO", "ExternalId":"10000502"}, {"SalesforceId":"02i2C000002PRMqQAO", "ExternalId":"10000501"}]
%var b = [
{
"Result": {
"errors": "",
"id": "02i2C000002PRMpQAO",
"success": "true",
"created": "true"
}
},
{
"Result": {
"errors": "",
"id": "02i2C000002PRMqQAO",
"success": "true",
"created": "false"
}
}
]
%var c = [{
"name": "GMC",
"subscriptionId": "10000501"
},
{
"name": "BUIC",
"subscriptionId": "10000502"
}]
---
b map ((payload1 , indexOfPayload1) -> {
success: payload1.Result.success,
created : payload1.Result.created,
(a filter ($.SalesforceId == payload1.Result.id) map ((variable2 , indexOfVariable2) -> {
ExternalId: variable2.ExternalId,
JSON : grab(variable2.ExternalId)
}))
})
Sep 07, 2018 at 03:04 PM, soumyajit22 answered with:
@ You can achieve this using groupBy function
%dw 1.0
%output application/json
%var a = [{"SalesforceId":"02i2C000002PRMpQAO", "ExternalId":"10000502"}, {"SalesforceId":"02i2C000002PRMqQAO", "ExternalId":"10000501"}] groupBy $.ExternalId
%var b = [ { "Result": { "errors": "", "id": "02i2C000002PRMpQAO", "success": "true", "created": "true" } }, { "Result": { "errors": "", "id": "02i2C000002PRMqQAO", "success": "true", "created": "false" } } ] groupBy $.Result.id
%var c = [{ "name": "GMC", "subscriptionId": "10000501" } ,{ "name": "BUIC", "subscriptionId": "10000502" }]
---
c map {
success : b[a[$.subscriptionId].SalesforceId[0]].Result.success[0],
created : b[a[$.subscriptionId].SalesforceId[0]].Result.created[0],
"JSON": {
"name": $.name,
"subscriptionId": $.subscriptionId
}
}
Thanks
Sep 07, 2018 at 03:19 PM, vijaykumar63 answered with:
@soumyajit22 thanks for your reply , but I was getting some null values
[
{
"success": null,
"created": null,
"JSON": {
"name": "GMC",
"subscriptionId": "10000501"
}
},
{
"success": null,
"created": null,
"JSON": {
"name": "BUIC",
"subscriptionId": "10000502"
}
}
]
Sep 07, 2018 at 03:26 PM, soumyajit22 answered with:
@vijaykumar63 Strange. It is working for me. See the screenshot below
Sep 07, 2018 at 03:46 PM, vijaykumar63 answered with:
@soumyajit22 ok, may be issue from my end. Thanks for your answer, appreciate it