Looping create/update to Database

I’m relatively new to n8n, but no stranger to writing code and working with databases. I understand logical flows of code, but working to understand how to apply that to n8n.

I’m attempting to iterate over a list of jira tasks. If the task doesn’t exist in my nocodb, create it. It it DOES exist, then update the record. Eventually I’ll do more, but that’s my basics

This is what it looks like today, which follows that logic. However, it only sort of works at best. 3 works, gets 3 items. 2 of which are in my database. 1 always runs and updates, sometimes the two in the DB run fine. But the creation step never triggers.

As I understand it I really shouldn’t need the loop, but I’m at a loss to find a good example/tutorial as to how to handle a situation where I have some data but not others. Any tips/suggestions would be appreciated.

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

You should be able to take advantage of the ‘Compare datasets’ node to do this. That way you only load the NocoDb entries once, not once for every Jira ticket. The workflow would look something like this:

2 Likes

Thanks David. That’s helpful. A while after I posted this I found a “solution” that was similar in concept. Couldn’t revoke my post since it was in moderation, but I’m glad I didn’t.

I went with a merge dataset option which “works” but your option is better. I have a couple If branches to handle data mismatch on specific fields only, where as yours eliminates the need for those AND (I suspect) handles a lot more data checks more efficiently.

In short, as a coder I’m used to the more linear thought of “I go get X, then I can check against Y, make a decision, then take action Z”. Where as with n8n you can take multiple actions effectively at the same time. Also the fact that it effectively loops everything built in is… different.

Yes, n8n allows you to do what are effectively set operations on your data. But because you can also put your items in a loop and process them one by one, it actually supports both approaches. It’s just that the ‘sets’ way is often more efficient since you only load the data once.

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