AnsweredAssumed Answered

Mapping logic required....!!

Question asked by subhash_nalluri on Apr 25, 2018
Latest reply on Apr 25, 2018 by 51662476

Hello Everyone,

I am brainstorming  to break this logic-

Below is the Input, which has invoices and bill line items. Input has invoices and line items. Few invoices are repeated with different line items. So my question is- How should I combine line items with same invoice as an array under invoice header??

 

Input:

 

{
"INVOICES": [
{
"INVOICE": {
"DINVOICENO": 01,
"DETAILS": {
"ACTIVE": "Active",
"VENDORID": "ABC 22",
"VENDORNAME": "ABC Depot",
"INVOICENO": "101010",
"INVOICEDATE": "04/24/2018",
"DUEDATE": "05/31/2018",
"GLPOSTINGDATE": "04/24/2018",
"DESCRIPTION": "This is Description",
"BILLLINEITEMAMOUNT": 100,
"BILLLINEITEMACCTNO": 9814,
"BILLLINEITEMDESC": "Books",
"BILLLINEITEMUNITCOST": 100
}
}
},
{
"INVOICE": {
"DINVOICENO": 02,
"DETAILS": {
"ACTIVE": "Active",
"VENDORID": "ABC 22",
"VENDORNAME": "ABC Depot",
"INVOICENO": "101010",
"INVOICEDATE": "04/18/2018",
"DUEDATE": "05/31/2018",
"GLPOSTINGDATE": "04/18/2018",
"DESCRIPTION": "This is Description",
"BILLLINEITEMAMOUNT": 500,
"BILLLINEITEMACCTNO": 7634,
"BILLLINEITEMDESC": "Pens",
"BILLLINEITEMUNITCOST": 10
}
}
},
{
"INVOICE": {
"DINVOICENO": 03,
"DETAILS": {
"ACTIVE": "Active",
"VENDORID": "ABC 22",
"VENDORNAME": "ABC Depot",
"INVOICENO": "202020",
"INVOICEDATE": "04/18/2018",
"DUEDATE": "05/31/2018",
"GLPOSTINGDATE": "04/18/2018",
"DESCRIPTION": "This is Description",
"BILLLINEITEMAMOUNT": 50,
"BILLLINEITEMACCTNO": 5788,
"BILLLINEITEMDESC": "Sticky",
"BILLLINEITEMUNITCOST": 50
}
}
}
]
}

 

 

Expected output:

 

{
"obj" : {
"ACTIVE": "Active",
"VENDORID": "ABC 22",
"VENDORNAME": "ABC Depot",
"INVOICENO": "101010",
"INVOICEDATE": "04/24/2018",
"DUEDATE": "05/31/2018",
"GLPOSTINGDATE": "04/24/2018",
"DESCRIPTION": "This is Description",
"billLineItems" : [ {
"BILLLINEITEMAMOUNT": 100,
"BILLLINEITEMACCTNO": 9814,
"BILLLINEITEMDESC": "Books",
"BILLLINEITEMUNITCOST": 100
}, {
"BILLLINEITEMAMOUNT": 500,
"BILLLINEITEMACCTNO": 7634,
"BILLLINEITEMDESC": "Pens",
"BILLLINEITEMUNITCOST": 10
} ]
},
{
"ACTIVE": "Active",
"VENDORID": "ABC 22",
"VENDORNAME": "ABC Depot",
"INVOICENO": "202020",
"INVOICEDATE": "04/18/2018",
"DUEDATE": "05/31/2018",
"GLPOSTINGDATE": "04/18/2018",
"DESCRIPTION": "This is Description",
"billLineItems" : [ {
"BILLLINEITEMAMOUNT": 50,
"BILLLINEITEMACCTNO": 5788,
"BILLLINEITEMDESC": "Sticky",
"BILLLINEITEMUNITCOST": 50
}]
}
}

 

 

Could someone please help me out!! 

 

Thanks in Advance,
Subhash.

Outcomes