Loop - How to loop based on List Item Count?

Have my free plan upgraded to personal.
but still not familiar with Bubble.io Loop Logic.

My Apps will gather a List of Text

  1. I need to run a loop to create new Database Item based on ( Item Count in the List )


  1. I cant found the option on how to achieve the Loop for X Times
    X = List Item ( Count )

  2. also I needed the i (index of the loop)
    eg, this is the 3rd time in the loop
    data = list-#item 3

---- can any senior here show me some light about Bubble.io Loop? ----
Thanks in advance.

If I understand your question correctly, you’re trying to create a database entry (a thing) for each of the text items in the list, yes?

In which case there’s no need to do any looping if you’re using a ‘schedule API workflow on a list’, which you appear to be from your screenshot.

Schedule an API workflow on a list of things will run that workflow on each thing in the list you specify - so in your case (assuming your API workflow is creating a thing), if your list of texts count is 3, then the workflow will be run 3 times, once on each of the 3 texts in the list.

You just need to set the ‘orederd-item’ to ‘this text’

Alternatively, you can use a recursive (looping) workflow instead of running the workflow on a list.

In that case you’ll need to set up the backend workflow to re-schedule itself, with the same list of texts it received, minus the text it’s just run on, the use Schedule An API Workflow (not on a list) from the front end to trigger it. And you’ll need to set up conditional logic so it stops running once all the items have been worked on (there are several ways to do that, but using the count of the texts is probably the easiest). You might also want to look at the List Popper plugin if you’re going to run a recursive workflow.

To be honest, for this particular use case, I personally wouldn’t bother running a recursive workflow (unless there is some specific reason why you need/want to) - running the API workflow on a list should work just fine for this.

On a side note, and without knowing anything about your app, is using text here the best thing to be doing? Might it be simpler, and more logical to use database objects (things) instead of text (I’m assuming your text relates to items on the menu, so why not just refer to those items instead of some text value?)

1 Like

Thanks for your insightful reply. will look into it.

Also, I with to share more detail on my app and my decision, let see you can give me better suggestion.

you can visit this link : [Am I Doing Right?] Database Logic - Performance POV

  • because I have the Apps to store User selection ( order ) within browser memory,

  • so I have created a state in element to hold List of texts.

  • why it is text?

  • because Bubble.io only have LIST function.
    - it cant record duplicated item, example the order is 2x cola.

  • so I have an identifier on each order to make them unique, even is ordering same item twice.

----- Thanks for your times -----
----- will study your reply about the loop 1st ----

1 Like

once on each of the 3 texts in the list.
My Friend, i was haft-way there, manage to loop the Workflow exactly based on List (Count)
( Thanks )
but i still unable to locate how to pass that data on each loop
image

  • Each the new data i create contain the Full List ( all item )
  • how do i refer the List#(based on loop index) when creating new data.

If you’re using a recursive workflow for this (as I’m assuming you are now) instead of running a workflow on a list of things, if you want to get the list item’s index, I’m pretty sure you can’t do that in standard Bubble, so you’ll have to create another list (of numbers) along with the list of texts.

Alternatively, if you use the List Popper plugin, you can set a list state on the backend and access the item’s indices directly.

I’m not entirely sure what you’re asking, and cant tell what your screenshot relates to - so I’m not sure what other guidance to give here…

But if you’re struggling with the concept there are a number of posts in the forum that might help.

I’m not sure you need to refer to the item number (it depends what you’re trying to do) - you can just remove one item from the list, and then run the workflow again on the remaining list, until there is only 1 item remaining - at which point you can end the workflow.

1 Like