Switch node, how to pass/access values from one switch route to the next inside a loop?

I simplified my workflow below. Basically I loop over a number of items. From the first item url I grab certain data that I don’t want to have to grab again for all the others item urls but just use/reference. However, how do I get to the returned data from the first switch in the next/else switches. So I want to refer to the values ABCD from Edit Fields in the html3 node’s css selector.

Information on your n8n setup

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

Seems the problem lied in the .item which needs to be .first()

By default when you drag the value in it sets it as .item but in fact it needs to be .first() here. Like that it works.

1 Like

Hi @jimvh ,

tbh, I cannot really follow on what you want to achieve by applying properties from one website to other websites, as they will most likely all be different in content and structure.

I can see, though, that you are struggling with loops and flow logic. For most scenarios, you do not need loops at all, as the nodes iterate through all incoming items anyway.

If you want to populate new fields deriving from one specific item in your given dataset and make them available to all items afterwards, I would suggest a simplified approach like in the workflow below.

As I said, I am not sure if this captures your intention, but maybe it’s a pointer into the right direction. Let me know if it helps.

Cheers, Ingo

Hi @Ingo , like I mentioned, it’s solved now. This is indeed a bad example but in fact I have it scrape our blog website where I let ai figure out the title and text css selectors based on the first url and for the next urls I just let it fetch the titles and articles based on the selectors mentioned in the first loop. I don’t want to call OpenAI for each article. Loop is indeed not required but I’ve added it for scraping purposes. We have about 260 articles to scrape and I may have to implement a wait or something like that so that is finishes them all in one go. I started from the sitemap index file. Works great now. I’m new to N8N so I’m still figuring out the formatting and logic. I’ll be adding them to a vector db next so clients can chat/talk to our blogs. Just experimenting a bit.

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