Skip to main content
nidhipal
Gold ⭐️
Apr 16, 2024 7:59 PM UTC
Question

How to apply a condition on a map of a nested list using RecordPath language in UpdateRecord in Nifi

The feed json is like below:

[
{
"orderId": "10000",
"orderItems": [
{
"orderItemSeqId": "10001",
"productIdentifications": [
{
"productIdentificationTypeId": "SKU",
"idValue": "98706"
},
{
"productIdentificationTypeId": "UPCA",
"idValue": "98788"
},
{
"productIdentificationTypeId": "HS_CODE",
"idValue": "98790"
}
]
},
{
"orderItemSeqId": "10002",
"productIdentifications": [
{
"productIdentificationTypeId": "SKU",
"idValue": "98690"
},
{
"productIdentificationTypeId": "UPCA",
"idValue": "98698"
},
{
"productIdentificationTypeId": "HS_CODE",
"idValue": "98999"
}
]
}
]
}
]

Requirement- Prepare two new fields for each item of an order.

1. Style: idValue of productIdentification whose productIdentificationTypeId is SKU.

2. UPC: idValue of productIdentification whose productIdentificationTypeId is UPCA. 

The output json should be 

 

[
{
"orderId": "10000",
"orderItems": [
{
"orderItemSeqId": "10001",
"productIdentifications": [
{
"productIdentificationTypeId": "SKU",
"idValue": "98706"
},
{
"productIdentificationTypeId": "UPCA",
"idValue": "98788"
},
{
"productIdentificationTypeId": "HS_CODE",
"idValue": "98790"
}
],
"Style": "98706",
"UPC": "98788"
},
{
"orderItemSeqId": "10002",
"productIdentifications": [
{
"productIdentificationTypeId": "SKU",
"idValue": "98690"
},
{
"productIdentificationTypeId": "UPCA",
"idValue": "98698"
},
{
"productIdentificationTypeId": "HS_CODE",
"idValue": "98999"
}
],
"Style": "98690",
"UPC": "98698"
}
]
}
]

 

Tried this property in UpdateRecord using RecordPath language but it didn't work.

name: "/orderItems[*]/Style"

value: "/orderItems[*]/goodIdentifications[./goodIdentificationTypeId='SKU']/idValue"

 

2 replies

DianaTorres
Community Manager
Community Manager
Apr 16, 2024 8:43 PM UTC

@nidhipal Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our NiFi experts @SAMSAL @joseomjr  who may be able to assist you further.

Please keep us updated on your post, and we hope you find a satisfactory solution to your query.

Translate
Regards, Diana Torres, Senior Community Moderator
gurveen
Silver ⭐️
Apr 17, 2024 10:23 AM UTC

Hi @nidhipal 

Looks like you figured this out here, https://community.cloudera.com/t5/Support-Questions/Possible-RecordPath-to-fetch-data-from-a-list-based-on-a/m-p/386665/highlight/true#M246104

The added RecordPath works.
 ../goodIdentifications[*][./goodIdentificationTypeId = "SKU"]/idValue

Thank you!

Translate