cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve a list within another array list

Deepti
New Contributor

Hi there,

I have one input json like as follows:

{
    "isValid": true,
    "logId": "9IE9BkOwxvrCwn_Ot7p4o-1699858392",
    "contractId": 1,
    "erpVendorId": "VID123",
    "erpVendorName": null,
    "erpVendorLocationId": "VSID789",
    "vendor": [
      {
        "Id": "2432",
        "id": 2432,
        "DBNo": "121212",
        "Name": "",
        "Website": "",
        "hubPath": "",
        "Instance": "331",
        "LegalName": "",
        "LongLabel": "",
        "SourceApp": "kahua_CompanyManager",
        "entityDef": "kahua_CompanyManager.kahua_Company",
        "InstanceId": "11501463",
        "ShortLabel": "",
        "DetailLabel": "Company: ",
        "IsPublished": "True",
        "PartitionId": "0",
        "AppNameLabel": "[AppLabel]",
        "CompanyEmail": "",
        "GovernmentId": "1234",
        "VendorNumber": "1234",
        "MarkupEnabled": "False",
        "IsPrequalified": "False",
        "CreatedDateTime": "\"2018-02-26T11:54:51.153\"",
        "IsDomainCompany": "True",
        "CompanyEntryType": "Construction",
        "IsExchangeEntity": "False",
        "ModifiedDateTime": "\"2021-07-01T15:12:16.71\"",
        "DomainPartitionId": "0",
        "IsPreferredVendor": "False",
        "outwardReferences": [

        ],
        "PortableViewInstance": "331",
        "IsInSyncWithCommunity": "False"
      }
    ],
    "description": "PO3",
    "createdDt": "2023-11-09T16:34:41.065Z",
    "sourceDocumentDate": null,
    "sourceStartDate": null,
    "sourceFinalCompletionDate": null,
    "shipToCode": "33857616",
    "sourceContractId": 34372838,
    "currencyCode": "USD",
    "sourceNumber": "KPO000000003",
    "totalAmount": "0",
    "operatingModel": "MP",
    "billingScope": "16",
    "projectId": 2,
    "project": {
      "projectId": 2,
      "clientCode": "LOCAL",
      "sourceDomain": "",
      "currencyCode": null,
      "erpProjectId": "ERPPOIO78945",
      "billingScope": "16 - Major Project Cost Plus EXP",
      "projectErpDetails": {
        "glBu": "12090",
        "budRefId": 89965
      },
      "location": {
        "financeId": "33857616",
        "country": "US"
      }
    },
    "requestorId": "TMacon",
    "targetCloseDate": "2023-12-31T23:59:59.999Z",
    "message": "This PO request has been successfully submitted to myBuy",
    "items": [
      {
        "description": "Architecture Fees",
        "quantity": null,
        "unitPrice": "1000",
        "total": "1000",
        "sourceId": "34372839",
        "sourceNumber": 1,
        "scopeOfWork": null,
        "projectActivity": {
          "chartCodes": [
            {
              "chartCode": {
                "uniqueCode": "7845",
                "supplementalType": "BOMA"
              }
            }
          ]
        },
        "type": "Item"
      },
      {
        "description": "02 Site Utilities",
        "quantity": null,
        "unitPrice": "1000",
        "total": "1000",
        "sourceId": "34372840",
        "sourceNumber": 2,
        "scopeOfWork": null,
        "projectActivity": {
          "chartCodes": [

          ]
        },
        "type": "Item"
      }
    ]
  }

and the desired output is as follows:

{
   "order": {
      "messageID": "9IE9BkOwxvrCwn_Ot7p4o-1699858392",
      "source": "",
      "entity": "US",
      "client": "LOCAL",
      "orderId": 34372838,
      "orderNumber": "KPO000000003",
      "orderName": "PO3",
      "version": 1,
      "orderType": "Requisition",
      "externalOrderReferenceNumber": "1",
      "externalOrderReferenceType": "PJM contract ID",
      "relatedOrderReferences": {
         "relatedOrderReference": {
            "relatedOrderNumber": "",
            "relatedOrderSystem": "",
            "relatedOrderType": ""
         }
      },
      "buyerCustomerParty": {
         "buyerId": "",
         "buyerCustomerExternalId": "",
         "buyerCustomerExternalReferenceTypeId": "",
         "buyerCustomerExternalReferenceTypeName": ""
      },
      "sellerSupplierParty": {
         "sellerID": "12090-VID123",
         "sellerSupplierExternalId": "",
         "sellerSupplierExternalReferenceTypeId": "",
         "sellerSupplierExternalReferenceTypeName": "",
         "sellerSupplierName": null,
         "sellerSupplierSiteId": "VSID789"
      },
      "delivery": {
         "deliveryLocationId": "917",
         "deliveryLocationDescription": "",
         "deliveryStartDate": "",
         "deliveryEndDate": "",
         "deliveryAttention": ""
      },
      "orderCreatedDate": null,
      "orderAmount": "0",
      "commercialModel": "MP",
      "currencyCode": {
         "code": "USD",
         "description": ""
      },
      "exchangeRates": {
         "exchangeRateDate": "",
         "baseTotalCost": "",
         "exchangeRate1": "",
         "exchangeRate2": "",
         "baseCurrencyCode": ""
      },
      "orderStatus": {
         "code": "Open",
         "description": ""
      },
      "paymentTerms": "",
      "shippingTerm": "",
      "requestedBy": {
         "contactName": "",
         "contactId": "US/TMacon"
      },
      "preparedBy": {
         "contactName": "",
         "contactId": ""
      },
      "comments": "",
      "orderLineItems": {
         "orderLineItem": [
            {
               "originatingOrderLineID": 1,
               "relatedOrderLineReference": {
                  "relatedOrderNumber": "",
                  "relatedOrderLineNumber": "",
                  "relatedOrderSystem": "",
                  "relatedOrderType": ""
               },
               "lineItemName": "Architecture Fees",
               "lineItemType": "Item",
               "lineItemNumber": "34372839",
               "lineClosedDate": "",
               "lineItemDetails": {
                  "modelName": "",
                  "manufacturer": "",
                  "sellerItemCatalogId": "",
                  "sellerItemId": "",
                  "commodityGroupCode": "",
                  "commodityClassificationCode": "",
                  "commodityDescription": ""
               },
               "locationId": "33857616",
               "buildingName": "",
               "lineDeliveryDetails": {
                  "deliveryLocationId": "33857616",
                  "deliveryLocationDescription": "",
                  "deliveryStartDate": null,
                  "deliveryEndDate": null,
                  "deliveryAttention": ""
               },
               "quantity": null,
               "quantityReceived": "",
               "quantityInvoiced": "",
               "quantityRemaining": "",
               "unitCost": "1000",
               "baseUnitCost": "",
               "receivedUnitCost": "",
               "lineItemAmount": "1000",
               "lineItemBaseAmount": "",
               "unitofMeasure": {
                  "code": "EACH",
                  "description": ""
               },
               "currencyCode": {
                  "code": "USD",
                  "description": ""
               },
               "lineItemDescription": "Architecture Fees",
               "lineItemStatus": {
                  "code": "",
                  "description": ""
               },
               "termsConditions": "",
               "lineItemComments": null,
               "contractDetails": {
                  "contractNumber": "KPO000000003",
                  "contractScope": "",
                  "activity": "20_7845_9999",
                  "billType": ""
               },
               "glAccountCode": {
                  "glAccountCode": null,
                  "bomaCode": 7845
               },
               "additionalCoding": {
                  "originatingProjectNumber": "KPO000000003",
                  "workOrderNumber": 89965,
                  "workOrderDetails": {
                     "workOrderClass": "",
                     "workOrderType": "",
                     "workOrderTypeDescr": "",
                     "workOrderDescription": "",
                     "woAgreementType": "",
                     "woContractNumber": "",
                     "woBillType": "",
                     "woClientReference": "",
                     "woCustomer": "",
                     "woCustomerParent": "",
                     "woCustomerAR": "",
                     "woLocation": "",
                     "woClientCostCenter": ""
                  }
               }
            },
            {
               "originatingOrderLineID": 2,
               "relatedOrderLineReference": {
                  "relatedOrderNumber": "",
                  "relatedOrderLineNumber": "",
                  "relatedOrderSystem": "",
                  "relatedOrderType": ""
               },
               "lineItemName": "02 Site Utilities",
               "lineItemType": "Item",
               "lineItemNumber": "34372840",
               "lineClosedDate": "",
               "lineItemDetails": {
                  "modelName": "",
                  "manufacturer": "",
                  "sellerItemCatalogId": "",
                  "sellerItemId": "",
                  "commodityGroupCode": "",
                  "commodityClassificationCode": "",
                  "commodityDescription": ""
               },
               "locationId": "33857616",
               "buildingName": "",
               "lineDeliveryDetails": {
                  "deliveryLocationId": "33857616",
                  "deliveryLocationDescription": "",
                  "deliveryStartDate": null,
                  "deliveryEndDate": null,
                  "deliveryAttention": ""
               },
               "quantity": null,
               "quantityReceived": "",
               "quantityInvoiced": "",
               "quantityRemaining": "",
               "unitCost": "1000",
               "baseUnitCost": "",
               "receivedUnitCost": "",
               "lineItemAmount": "1000",
               "lineItemBaseAmount": "",
               "unitofMeasure": {
                  "code": "EACH",
                  "description": ""
               },
               "currencyCode": {
                  "code": "USD",
                  "description": ""
               },
               "lineItemDescription": "02 Site Utilities",
               "lineItemStatus": {
                  "code": "",
                  "description": ""
               },
               "termsConditions": "",
               "lineItemComments": null,
               "contractDetails": {
                  "contractNumber": "KPO000000003",
                  "contractScope": "",
                  "activity": "20_null_9999",
                  "billType": ""
               },
               "glAccountCode": {
                  "glAccountCode": null,
                  "bomaCode": null
               },
               "additionalCoding": {
                  "originatingProjectNumber": "KPO000000003",
                  "workOrderNumber": 89965,
                  "workOrderDetails": {
                     "workOrderClass": "",
                     "workOrderType": "",
                     "workOrderTypeDescr": "",
                     "workOrderDescription": "",
                     "woAgreementType": "",
                     "woContractNumber": "",
                     "woBillType": "",
                     "woClientReference": "",
                     "woCustomer": "",
                     "woCustomerParent": "",
                     "woCustomerAR": "",
                     "woLocation": "",
                     "woClientCostCenter": ""
                  }
               }
            }
         ]
      }
   }
}

Tried achieving same using mapper expression variables but still couldn't get to the final outcome. Urgently need any help here (so specifically am looking for a way to drill down to and use projectActivity-->chartCode object within items array, here for activity we have a logic in place to look for specific supplementalType value, fetching wherever we have it as 'BOMA'). Please let me know in case additional details are needed from my end.

Thanks,

Deepti

1 ACCEPTED SOLUTION

koryknick
Employee
Employee

HI @Deepti - update the second Mapper expression to the following:

$items
.map(x=> x.merge(
{ "additionalCoding" : { "workOrderNumber" : $project.projectId } 
,  "contractDetails" : { "workOrderNumber" : $project.projectId } }
)
)

So rather than an Object.extend(), we'll use Object.merge() to do a deep merge of the object, allowing us to also add the workOrderNumber into the existing contractDetails sub-element.

Hope this gets you closer to your goal!

View solution in original post

8 REPLIES 8

koryknick
Employee
Employee

@Deepti - please unzip and import the attached pipeline.  Since you are already familiar with jsonPath and Array functions, I will not go into detail on the solution.  Please let me know if you have any questions.  

Hi @koryknick ,

Thanks for your response, and I understood the solution provided, was following same path but couldn't make it work. However, I need to tweek this a bit further where I would need this projectid coming from outside also being mapped in items array list.

{
   "order": {
      "orderLineItems": {
         "orderLineItem": [
            {
               "lineItemName": "Architecture Fees",
               "unitCost": "1000",
               "contractDetails": {
                  "activity": "20_7845_9999",
                  "workOrderNumber": "2"
               },
               "additionalCoding": {
                  "workOrderNumber": "2"
               }
            },
            {
               "lineItemName": "02 Site Utilities",
               "unitCost": "2000",
               "contractDetails": {
                  "activity": "20_null_9999",
                  "workOrderNumber": "2"
               },
               "additionalCoding": {
                  "workOrderNumber": "2"
               }
            }
         ]
      }
   }
}

So, if I want the output to look like this instead (where we have some elements from inside list and some from outside), then how will we achieve that as this is just the snippet of what I was looking for but, in reality I do need to combine some inside and outside array list objects. Looking forward to hearing back from you.

 

Thanks & Regards,

Deepti

koryknick
Employee
Employee

HI @Deepti - update the second Mapper expression to the following:

$items
.map(x=> x.merge(
{ "additionalCoding" : { "workOrderNumber" : $project.projectId } 
,  "contractDetails" : { "workOrderNumber" : $project.projectId } }
)
)

So rather than an Object.extend(), we'll use Object.merge() to do a deep merge of the object, allowing us to also add the workOrderNumber into the existing contractDetails sub-element.

Hope this gets you closer to your goal!

Thanks again @koryknick . It worked exactly as intended.