Problem with loop

Describe the problem/error/question

As the nocoDB-nodes does not support search requests I have to use a loop over all items to check for my matches.

Here’s the logic:

  • I get new data (think of it as lead)
  • I get all entries from table (“leads”)
  • If there is already an entry in table 1 the process stops. (That works correct.)
  • When no entry is found I grab all data from table 2 (“orders”)
  • Now I check the new lead with the existing orders.
  • If the lead already orders I add it to th elead table with status “ordered”. (That works correct.)
  • If not I want to add the lead with status “new”.

The issue is:
Adding the lead with status “new” does not happen once but as many times as I have orders in the table.

What is the error message (if any)?

No error messages.

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:**1.98.2
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu

I think this will be more straighfoward

But not sure why there are two nodes of creating orders. Maybe just leave one of them.

Or use filter agian to create the orders.

Thanks for the filter idea! But that part of the script works fine - but with the filter it is simpler.

There are two Add entry-Nodes to create entries in the lead table at the end:
The one at the “done” Path added with status “new”,
the other one with the status “ordered”. (The name of the node is misleading here. Sorry).

So if we find an order, we use the second one and the workflow stops.
If we do not find at the end of the 2nd loop the done-Part should create just one lead with status “new”. But it is call for as many elements as we have in the loop.

Oh yes. Forgot to mentioned that :

I use execute Once if the first IF node.

Because if there are multiple items. Like 3

It will cause the following part to execute 3 times

But I think you only need to execute once since you will get all the orders.

I have to check for every single order if the customer in that order is the one from the lead. So execute once can’t be the solution.

But it might help on the node “add entry new”. I’ll give it a try.

Add another image for better explain it!

I replace both loops with a aggregate-node and a code-node after that. This works fine.
Sadly the loop nodes seem to have a bug or something. :frowning:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.