05-20-2022 03:31 AM
Hi,
I would like to create the below outbound message from an incoming object array.
{
"root": {
"elementName": {
"@attributeName": "attributeValue",
"$": "elementValue"
},
"repeatedElement": [
{
"key": {
"@attr": "attr1",
"$": "key1"
},
"value": "value1"
},
{
"key": {
"@attr": "attr2",
"$": "key2"
},
"value": "value2"
}
]
}
}
Any suggestion please on the repeated elements, attributes, and values?
Thanks,
Deepak Shaw
Solved! Go to Solution.
05-20-2022 05:36 AM
Done, check the pipeline and let me know if this works for you. Can be made with multiple mappers or a JSON Schema as well, but this is simpler in terms of snaps usage.
05-20-2022 04:10 AM
Hi @bojanvelevski ,
I have updated the message with the minimum required fields. Hopefully
Group_By Fields output0.json (489 Bytes)
it gives a better understanding.
Regards,
Deepak.
05-20-2022 04:33 AM
It’s a bit confusing. repeatedElement it’s obviously the InvoiceLines object, but in your output sample, the objects contain only one key value pair:
{
"key": {
"@attr": "attr1",
"$": "key1"
},
"value": "value1"
}
While in the incoming data, one object contains four fields:
{
"LineNumber": "1",
"LineExtAmtExclTax": "7000",
"Employee": "Marlon Mangila",
"LineTax": "700"
}
Quickly use those fields to manually populate this output object from above, just as a reference.
05-20-2022 05:14 AM
Hi @bojanvelevski ,
Just to clarify here are input & output messages:
input:
[
{
"Header": {
"InvoiceNumber": "PRP100418",
"InvoiceDate": "29/04/2022",
"PaymentTermsDescription": "Net 7 days",
"CustomerRef": "C1381"
},
"InvoiceLines": [
{
"LineNumber": "1",
"LineExtAmtExclTax": "7000",
"Employee": "Marlon Mangila",
"LineTax": "700"
},
{
"LineNumber": "2",
"LineExtAmtExclTax": "800",
"Employee": "Elin Joe",
"LineTax": "150"
}
]
}
]
output:
{
"Invoice": {
"InvoiceNumber": {
"@attributeName": "PRP100418",
"$": "C1381"
},
"InvoiceLines": [
{
"LineNumber": {
"@LineExtAmtExclTax": "7000",
"$": "1"
},
"value": "Marlon Mangila"
},
{
"LineNumber": {
"@LineExtAmtExclTax": "8000",
"$": "2"
},
"value": "Elin Joe"
}
]
}
}
Looking forward to your suggestion.
Regards,
Deepak.
05-20-2022 05:36 AM
Done, check the pipeline and let me know if this works for you. Can be made with multiple mappers or a JSON Schema as well, but this is simpler in terms of snaps usage.
05-21-2022 03:58 AM
Hi @bojanvelevski , Amazing 🙂 it’s working as expected.
Can you please explain a bit about the code you have written in the map i.e.
$InvoiceLines.map(x=>{"LineNumber":{"@LineExtAmtExclTax":x.LineExtAmtExclTax,"$":x.LineNumber},"value":x.Employee})
Many thanks for your help,
Deepak Shaw.