Create records workflow with Javascript

I’m working on an inventory management app, and I like to create a workflow that accepts a quantity value (100) to generate the number of records based on that value. My guess is that I would need to create a custom javascript plugin with a loop adding these records to the database. What I’m less clear on is what credentials I’d need (host, port, user, password,database) to include in my Javascript. I read that Bubble uses a Postgres database so I’d have the port but what about the other values?

1 Like

You don’t need javascript or a plugin. Advanced guide: Creating Recursive Workflows and tracking their progress

Thanks @bubble.trouble I’ll review and revert back with any questions!

@bubble.trouble I reviewed the articles, but it’s not what I’m looking for. The articles discusses looping over an existing list not creating a new one.

Then see here: How to Create Data in Bulk in Bubble.io | Bubble.io Tutorial - YouTube

Thanks @bubble.trouble I’m familiar with this method, but it also leverages existing data. I need to create new records based on a quantity value. Is this not possible with a Javascript plugin?

You can do this in Vanilla Bubble (no plugins or custom JS needed)…

You can simply run a recursive workflow 100 times (or however many times you like) by passing that number as a parameter into the workflow (or you could use a list of numbers, and run the workflow once for each number in the list… or use a list of numbers to generate the data via the API Data Bulk Create endpoint)…

Edit: ok, so you do need a plugin to create a list of numbers…

@adamhholmes you don’t need a plugin. Import a csv with values 1-100 (you can generate this in a spreadsheet in a couple of seconds). Import it into a data type NumberList and then loop over the data type.

1 Like

Thanks @bubble.trouble but that doesn’t provide the smooth UX that I’m looking for.

@adamhholmes do you have a reference for how to build a recursive workflow? From what I’ve seen, you need to have an existing list, but I need to create one from scratch.

A recursive workflow is just a workflow that calls itself… no lists are required at all…

Here’s the simplest way to create a number of things using a recursive workflow…

  • Create a backend workflow that does whatever it is you want it to do (i.e. creates a new thing), and then reschedules itself…

  • Have a Number parameter (i.e. ‘Items’) on the workflow, and add a condition to the action that reschedules itself to only run when the ‘Items’ value is more than 1… and each time you schedule it just deduct 1 from the existing value…

That’s all there is to it…

Then just trigger it from your page, and pass the Number of Items you want to create into the ‘Items’ Parameter…

Of course, depending on exactly what you’re trying to do, you might need to make it more complex than that, but that’s the basic idea of how to do it…

If you want to use the Data API Bulk Create Endpoint to do this instead (which will probably be faster), just create a list of Numbers (using the ToolBox plugin) that is equal to the number of things you want to create, then just use ‘Format as text’ on that list… and for each item enter the JSON as per the Bubble docs…

2 Likes

Thanks @adamhholmes for the detailed response. I’ll try this out and revert back with my findings.

Thanks this performed as expected. Adding some screenshots to show what a built-out flow would look like.

Screenshot 2022-12-22 155804



1 Like