Nested Loops and Data

Hello there,

Once upon a time, we looped like this:

for (i=0; i< somevalue; i++) {

do stuff;

}

While the data in the loop was not available below it, the data prior to the loop was available inside the loop.

I have a nested loop and the consequences of data not getting pushed forward is catastrophic.

The n8n AI assures me that all I need is a merge, or a summarizer, and by the way I have to uplevel nested data using set nodes because the iterator can’t see past the first level of nested incoming data.

All I’m trying to do is loop through youtube playlists, then for each playlist, gather all video titles and descriptions. I want each playlist and its associated video titles/descriptions to feed into the next step as packets.

The output is hundreds of videos instead of a set of playlists and associated videos.

The AI tells me I’m getting 352 items instead of 11 packets is because the inner video loop has lost access to the outer loop playlist ids.

I did a search and saw someone discussing sub workflows, which kind of blew my mind as separating the logic paths solving this missing data seems implausible.

As I said to the AI, this seems like a major N8N architecture speed bump.

SURELY there is a standard procedure for

for (i=0; i< SOMETHING; i++) {
for (j=0; j< SOMETHINEELSE; j++)
}}

That was stable 30 years ago. But looping over videos is apparently impossible today.

Tell me there’s a standard procedure for this kind of looping?

Thank you and gratefully,
Caroline

1 Like

Hello @Caroline_Bogart1

Looping through playlists is possible with n8n. Do you have a workflow you can share? I can help you through the logic.

Here’s a video on how to upload your workflow in this chat.

pasteworkflow

I could show you the workflow as it is after hours of attempts but it’s a mess. The aI hallucinated a bunch of solutions that it then said oh yeah, that doesn’t work. It’s just a simple:
For each playlist, get videos
Group all video title-descriptions
Pair playlist title and description with video titles/descriptions
Give to AI for processing.
Loop through all playlists this way.

This is how you should loop over each playlist and get the video details. Once the loop node is done, you can use the data as needed. Let me know if you need further assistance with disecting the data further into a specific format

2 Likes

Reading you request again, this is how you can build a prompt input for all videos per playlist and ask an AI Agent to process the data. Change the AI System prompt to what you want to do with the data:

2 Likes

Thank you SO MUCh!

Many, many thanks. This is the final product.

2 Likes

Nice! Is it doing exactly what you need? Shout if you need more help

Please mark the solution on my post. It helps with my stats.

thank you for telling me about that (mark solution), I am so grateful for your assistance, the AI was gaslighting the heck out of me.

Yes it’s exactly what I wanted, and i’ve also learned a pattern that makes a lot of sense. Thank you!!

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