Filter nodes via Entity transformer

I’ve the next situation:

  1. incoming configuration > Merged Storage
    This gives a array of objects eg (Without the first! so, directly a array:

[
{ “id”: 1, “status”: “new”},
{ “id”: 2, “status”: “processed”},
etc…
]

  1. A route which starts with ‘Chain multiply entity transormers’
  2. Node, transform nodes (Key accessor)
  3. Data Transformer > Execute entity transformers

In step 4 I have 3 transformers:

a: checks ‘status’ and adds a KEY in the node (confirm = true or false)
b: Data Transformer > filters > value condition (confirm == true)
c: delete entity from storage

as last (step 5) I generate one array with only the ID’s from al the entities, eg:

{
2, 3
}

the problem is the B (Filter)
the error:

The number of entities returned by the entity transformer should be exactly one, received 0 entities

"class": "Magement\\Entity\\Transformer\\UnexpectedAmountException",
        "message": "The number of entities returned by the entity transformer should be exactly one, received 0 entities",
        "code": 0,
        "file": "/resources/fileshare/deployer/releases/2023-08-10-10-40-43-83f81c7/vendor/magement/entity/src/Transformer/ListTransformerWrapper.php:53"

Right now,. i’m a little bit out of options…

The main goal:

  • fetch all the entiies
  • add the extra key (confirm)
  • filter them base the ‘confirm’ key
  • delete and create one array with the IDs only to send it to a ‘outgoing’

Hi Tim,

Inside an “Execute entity transformers”, you cannot separate (branch) an entity into multiple entities. You also cannot use a data entity filter that may filter out an entity (0 entity).

If you want to filter an object within an array, you can use a node filter inside a Node transformer, such as below.

Alternatively, you can filter them using a JMESPath outside the Node transformer, such as below.

But this way, the filtered need to be put in another property instead of directly filtering the array in the root of the entity.

Aah alright, I got it working!

Just add a ‘nodes, transform nodes’ for each step and it’s working well

thanks

We are glad to hear that you managed to get it works.

It was our pleasure to help! Feel free to mark the answer as a solution if it solves your issue.
Have a good day!