Filter grandchild based on value in grandchild field

hi there,

I have the attached json message thats coming in this structure shown below. I need to filter the list in the Orderlines array if the status has “soft_closed_for_receiving” or “soft_closed_for_invoicing”. And if after filtering, if the array is empty then route it to a different mapper snap.

I tried filter snap but not working out. any guidance greatly appreciated.

sample_json.json (9.1 KB)

Thanks
Manohar

Hey @manohar,

The Filter snap functionality is based on the incoming objects, so for a specific condition, the filter snap will either pass or filter out that object. One way of filtering an array is with an expression in a Mapper snap.

I believe something like this should work:

$payload['order-lines'].filter(x=>x.status matches "soft_closed_for_receiving" | "soft_closed_for_invoicing").length > 0

If the result is false than the array is empty.

Thank you very much @bojanvelevski.

sorry I was not clear enough.

Step 1. I need to filter out the Lines that have these 2 values. so the result List will have lines that have status other than the 2 values.

Step 2. now route based on if the list count is greater than 0 or if its 0.

any pointers for this.

Thanks
Manohar

Then the expression will suffer a minor change:

$payload['order-lines'].filter(x=>!(x.status matches "soft_closed_for_receiving" | "soft_closed_for_invoicing")).length > 0

1 Like

Thank you again @bojanvelevski that did the trick.

I appreciate your help.

Manohar