Forum Discussion
5 Replies
- koryknickEmployee
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!
- DeeptiNew Contributor II
Hi bojanvelevski, I've read through a number of your insightful responses to other posts here, so I know you'll have something to offer me as well. Anticipating a response from you.TIA.
Deepti
- DeeptiNew Contributor II
Hi koryknick ,
My bad, please find below a simplified version of same:
Input:
{ "project": { "projectId": 2 }, "items": [ { "description": "Architecture Fees", "unitPrice": "1000", "projectActivity": { "chartCodes": [ { "chartCode": { "uniqueCode": "7845", "supplementalType": "BOMA" } } ] } }, { "description": "02 Site Utilities", "unitPrice": "2000", "projectActivity": { "chartCodes": [] } } ] }
Desired output:
{ "order": { "orderLineItems": { "orderLineItem": [ { "lineItemName": "Architecture Fees", "unitCost": "1000", "contractDetails": { "activity": "20_7845_9999" }, "additionalCoding": { "workOrderNumber": "2" } }, { "lineItemName": "02 Site Utilities", "unitCost": "2000", "contractDetails": { "activity": "20_null_9999" }, "additionalCoding": { "workOrderNumber": "2" } } ] } } }
Mapping I tried inside mapper:
mapping expression I used:
$items.map(val=>{"lineItemName":val.description,"unitCost":val.unitPrice,"contractDetails":{"activity":'20_'+jsonPath($,"items[*].projectActivity.chartCodes[*].chartCode").find(x=>x.supplementalType=='BOMA').uniqueCode+'_9999'},"additionalCoding":{"workOrderNumber":JSON.stringify($project.projectId)}})
It gives me output as follows:
{ "order": { "orderLineItems": { "orderLineItem": [ { "lineItemName": "Architecture Fees", "unitCost": "1000", "contractDetails": { "activity": "20_7845_9999" }, "additionalCoding": { "workOrderNumber": "2" } }, { "lineItemName": "02 Site Utilities", "unitCost": "2000", "contractDetails": { "activity": "20_7845_9999" }, "additionalCoding": { "workOrderNumber": "2" } } ] } } }
So here, I tried many a ways to manipulate the BOMA value which should come as distinct, the way it shows up in input, like for item 1 we have value available but for item 2 we should get null (or any other value, as coming from source), but the final working mapping I could figure out is mentioned above and it's basically mapping first BOMA code encountered in all the list object values.
Appreciate any help here!
Please let me know in case additional details needed here.
Thanks,
Deepti
- alchemizContributor III
Hi Deepti ,
Good day. Hope this helps
{'order':{'orderLineItems': {'orderLineItem': $items.map( i=> { 'lineItemName': i.get('description'), 'unitCost': i.get('unitPrice'), 'contractDetails': { 'activity': ''.concat('20_', (i['projectActivity'].get('chartCodes',[]).find((x,y,z)=> x.get('chartCode',{}).get('supplementalType','') == 'BOMA') || {}).get('chartCode',{}).get('uniqueCode','null'), '_9999')}, 'additionalCoding': {'workOrderNumber': $project.get('projectId')} })}}}
Thanks,EmEm
- DeeptiNew Contributor II
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