How do I double-iterate through the elements according to the hierarchy?

Hey!
How to make two SplitInBatces nodes in one workflow that iterate over the elements according to the relative hierarchy?
I was not able to figure out how to set up a workflow for this kind of iteration.
I first need to take parent_A and iterate over all its children, and only then go to parent_B. Each child needs to be sent through the HTTP request node.
I hope I explained it clearly.

The problem is that I can’t even look at the result of the iterations when setting up the workflow (.
Not obvious work of the interface in this particular case.

Hey @Roket!

You can use the Function node to extract the child data from the parent and then connect it to the SplitInBatches node.

Are you using the Test Webhook URL? If you’re using running the workflow using the Production Webhook URL, you won’t see the data. You will have to check the executions to view the data.

harshil1712, thanks for the answer!
Unfortunately, I don’t write JavaScript code, so I can’t make full use of the function node.
I am trying to collect logic on standard nodes.

As for the webhook, I use test runs, but I can’t see the iterative execution in them. Some of the data is not obvious and is under the hood of the tuning process.

Hey @Roket!

You can use the following nodes in your workflow to Split the child data. Please note that you might have to make some minor changes to the Function node. In my example, the child data was inside the product key hence I used items[0].json.product.map. If your child data is nested inside a key with a different name, replace the product with that key’s name. Let me know if you have further questions.

Harshil1712, thanks again!
Yes, I use this code a lot in my workflows.
But, I still have one problem. How do I make the code below so that it is applied to every element of a merge node? It currently only applies to the first item.
In my case, after a merge node that returns more than 150 elements, the function node only processes the first element.


The code of this function node:

const result = [];
for (const item of items) {
  const json = item.json;
  let taxInputs = {};
  let metaInputs = {};
  for (const key of Object.keys(json)) {
    if (key.includes('tax_input') && key !== 'tax_input') {
        taxInputs[key] = json[key].split(',').map(item => item.trim()).filter(item => !!item);
    }
      if (key.includes('meta_input') && key !== 'meta_input') {
        metaInputs[key] = json[key];
    }
  }
  result.push({
    json: {
        action: "update_post",
        post_id: json['post_id'],
        post_title: json['post_title'],
        post_status: json['post_status'],
        post_type: json['post_type'],
        tax_input: taxInputs,
        meta_input: metaInputs,
    }
  })
  taxInputs = [];
  metaInputs = {};
  return result
}

Items in a merge node:


Only two executions:

Hey @Roket, can you also share the output of the Function node?

The badge on the Function node shows 2 because the previous node has two executions. The Function node will process all the data.

Here’s another example of a workflow with an additional SplitInBatces node. Only here the problem is that on the second iteration the loop is terminated for the next 177 units of elements.

Hey!
This issue remained unresolved.
Can anyone please help?