Created 10-11-2022 07:34 AM
Hi guys,
hope anyone can point me on the right direction.
I have the following flow file:
[ {
"version" : "5",
"type" : "REPORT",
"dp_code" : "DHA592",
"field4" : "83482227299911",
"field5" : "83482227299911",
"platform_name" : "GHESTEM LA CHAPELLE",
"field7" : "01143200",
"field8" : "72801371220938",
"field9" : "72801371220938",
"carrier_name" : "",
"shipper_name" : "",
"field12" : "",
"consignee_name" : "",
"consignee_code" : "",
"consignee_address" : "",
"consignee_city" : "",
"field17" : "",
"ldc_number" : "",
"ldc_date" : "",
"shipment_number" : "2022115144",
"shipment_code" : "2022115144/SH",
"field22" : "",
"field23" : "",
"field24" : "",
"field25" : "liv.cfm",
"situation_code" : "LIV",
"justification_code" : "CFM",
"situation_date" : "20221003",
"feedback_date" : "202210061222",
"anomaly_packages_number" : "",
"comments" : "",
"new_appointment_date" : "",
"field33" : "",
"field34" : "",
"field35" : "",
"assigned" : "",
"field37" : "",
"agreed_tax" : "",
"field39" : "",
"field40" : "20221006123304-3f621cf7-3",
"field41" : "",
"field42" : "",
"field43" : "",
"field44" : "212059",
"doc_url" : "",
"field46" : "",
"field47" : "",
"field48" : ""
}, {
"version" : "5",
"type" : "REPORT",
"dp_code" : "DHA592",
"field4" : "83482227299911",
"field5" : "83482227299911",
"platform_name" : "GHESTEM LA CHAPELLE",
"field7" : "01143200",
"field8" : "72801371220938",
"field9" : "72801371220938",
"carrier_name" : "",
"shipper_name" : "",
"field12" : "",
"consignee_name" : "",
"consignee_code" : "",
"consignee_address" : "",
"consignee_city" : "",
"field17" : "",
"ldc_number" : "",
"ldc_date" : "",
"shipment_number" : "2022115144",
"shipment_code" : "2022115144/SH",
"field22" : "",
"field23" : "",
"field24" : "",
"field25" : "",
"situation_code" : "POD",
"justification_code" : "CFM",
"situation_date" : "20221003",
"feedback_date" : "202210061208",
"anomaly_packages_number" : "",
"comments" : "",
"new_appointment_date" : "",
"field33" : "",
"field34" : "",
"field35" : "",
"assigned" : "",
"field37" : "",
"agreed_tax" : "",
"field39" : "",
"field40" : "20221006121304-3f61f8b6-3",
"field41" : "",
"field42" : "",
"field43" : "",
"field44" : "212059",
"doc_url" : "",
"field46" : "",
"field47" : "",
"field48" : "S"
}, {
"version" : "5",
"type" : "REPORT",
"dp_code" : "DHA592",
"field4" : "83482227299911",
"field5" : "83482227299911",
"platform_name" : "GHESTEM LA CHAPELLE",
"field7" : "01143200",
"field8" : "72801371220938",
"field9" : "72801371220938",
"carrier_name" : "",
"shipper_name" : "",
"field12" : "",
"consignee_name" : "",
"consignee_code" : "",
"consignee_address" : "",
"consignee_city" : "",
"field17" : "",
"ldc_number" : "",
"ldc_date" : "",
"shipment_number" : "2022115144",
"shipment_code" : "2022115144/SH",
"field22" : "",
"field23" : "",
"field24" : "",
"field25" : "",
"situation_code" : "AAR",
"justification_code" : "CFM",
"situation_date" : "20221003",
"feedback_date" : "202210061208",
"anomaly_packages_number" : "",
"comments" : "",
"new_appointment_date" : "",
"field33" : "",
"field34" : "",
"field35" : "",
"assigned" : "",
"field37" : "",
"agreed_tax" : "",
"field39" : "",
"field40" : "20221006121304-3f61f8b6-3",
"field41" : "",
"field42" : "",
"field43" : "",
"field44" : "212059",
"doc_url" : "",
"field46" : "",
"field47" : "",
"field48" : "S"
} ]
My need is to grab only one element of json file based on "situation_code" in a priority order.
To explain me well, situation code can have the following possible values:
The logic behind should be the following:
Grab only one entire element by evaluating at first POD as value, if found grab it, if not found then evaluate LIV and grab it in case, if not found then evaluate AAR and grab it, and so on until you found a possible value.
Many thanks for any hints
Created 10-11-2022 08:52 AM
Created 10-11-2022 07:49 AM
I believe you could use QueryRecord to take you in the right direction.
You could define properties to route files based on their situation code, for example:
Key: POD
Value: SELECT * FROM flowfile WHERE situation_code = 'POD' LIMIT 1
This would route 1 element in your input array where the code is POD to the new relationship "POD" (same as the dynamic property name).
This doesn't exactly match your case of retrieving an element only if higher priority codes weren't found, but perhaps you could use this example to get closer to a solution. Good luck!
Created 10-11-2022 08:22 AM
Thanks for the update, however that's is the problem.
The Query Record does not fit my needs cause cannot implement the logic.
Note that the json doesn't have always all situation codes, so the pseudo code should be:
Grab the element with sit_code = POD only if present, otherwise go further with others.
Any help is appreciate.
Many Thanks
Created 10-11-2022 08:52 AM
Created 10-12-2022 07:53 AM
Many thanks,
it works like a charm!