I’ve messed with this loop issue for long enough to confuse myself.
I’m using the SERP API to import Google News search results based on some keyword.
I want to take the first 20 results that have an author (some do not, so I skip those) and save them to the database as a thing called ‘related article’.
So, I scheduled the first workflow on a list (since the API returns a list of results… right?), where my iterator is called ‘count’, which is a number, and it starts at 0.
Then, I schedule the ‘loop’ workflow, where it creates the ‘related article’ thing, links that thing to a ‘parent post,’ and then schedule the API workflow again, with ‘count + 1’ iterator, and a safety stop at ‘count < 20’:
I wanted to loop through the first eligible 20 articles (where the author is not empty) and save them to the database.
However, here is what actually did save to the database: hundreds of duplicate results, and seemingly random and duplicate count system, that does not seem to follow the ‘count + 1’ formula
What am I missing? The logic doesn’t make sense to me. I’m sure it’s something simple.
Thank you for your time.
(*I am not using Google’s built in ‘position’ field that comes back from the API response, because I am filtering out some of the results. Not every result from the top 20 fits my criteria. I want to set up my own iterator/counting system.)
From what I see, you are not doing a recursive loop but a schedule on a list no? Why are you scheduling it again? If you want to create a loop, you need to schedule but not on a list. And pass all remaining items in the list to next loop.
Thanks for the quick reply.
I edited the title to reflect your corrections.
Apologies for the incorrect terminology.
Yes, I was trying to use a schedule a workflow on a list, thinking that was the way to accomplish what I was after.
Why am I scheduling it again: honestly, because several YouTube videos told me to. I don’t have a good understanding on how to create a for-loop with Bubble yet. New to this.
I’m following videos to learn. This is a result of several different how-to videos, so it’s the root of my problem. Courses generally address a ‘basic’ loop, but once you throw in a variable that isn’t in the instructional video, it’s easy to lose the plot.
What is the most efficient way to accomplish what I’m after? Schedule a workflow on a list?
Again, thank you for your time.
What I understand is that you want to create one article per thing in the list of result from Google news?
You should just schedule on a list. There’s no reason to do a loop for you case.
Video you checked probably don’t use a schedule on a list to start the workflow but just an initial trigger to schedule the loop that schedule itself after.
Your comments made me rebuild this workflow on a list and look at everything from scratch.
You are right, duplication was simply removed by not looping again. That should have been a no-brainer, but when I ran it the first time without the loop, I got no results in the database, hence watching other videos to fix a problem that now does not exist. Go figure.
I still haven’t figured out how to add an iterator/counter with a workflow on a list yet, but it is no longer crucial here.
I also found the correct way to limit the number of articles without iterating through a loop and a counter field.
If anyone is looking at this post n the future:
Limiting the number of items is set in the field ‘List to run on’ and adding ‘items until #20’.
Also, for those new to Bubble, this is probably the simplest, clearest explanation of adding items from an API via workflow on a list. Thank you, Jacob.