Forum Academy Marketplace Showcase Pricing Features

Deleting element from list of things deletes all similar elements

Hi,
I have a database which is comprised of a list of things. To make an easy example:
Test database has only one field called test1 with only one record which is: 1, 2, 4, 3, 4.

I want to be able to remove the 3rd item from that list of things which is a 4. So the resulting list that I want is 1, 2,3,4 but when I create the workflow and tell it to remove the 3rd item like so:
image
It will remove every element matching the 3rd element. So I end up with the list 1, 2, 3. I also tried changing the workflow to remove the last item instead of item#3 and it did the same thing.

How do I get it to only delete the 3rd item and not every item that matches the third item?
Thanks
Paul

1 Like

So apparently bubble does this on purpose. My work around is to append some text to the end of each element in the list of things to make each one unique. So instead of 1, 2, 4, 3, 4, I’ll have 1.a, 2.b, 4.c, 3.d, 4.e and then I’ll use regex to strip the .a or .b etc when it comes time to displaying this info.

1 Like

What is your exact use case here? I may look into building this feature out in a different way.

The first thing that came to mind is to create a field that is a list of a data type, instead of a list of text or numbers. This way, each item will be unique.

My exact use case is I have an API workflow that populates my database. Each api call populates one record in the DB and each record is comprised of a list of things 200 elements long. I have one field that is the category of each item in the list of things (i.e. sweater, long sleeve shirt, t-shirt, pants, etc). I have a different workflow that allows the user to remove a specific item from the list of things. It works fine for every other field as every other value is unique to one another but as you can imagine, sweater applies to multiple items in the list and when the nth item gets removed, anything in the item category field that is the same as sweater also gets removed.

I’m not sure I fully understand your suggestion. I tried looking to see how to add a list of datatypes but am not seeing it in the list:

Thanks for your help @wesfrank

1 Like

Thanks for the clarification, @paul29. Helps me see where you’re coming from a bit better.

I don’t think I’ll be able to answer your question completely because there is still some information missing, but I should be able to point you in the right direction.

Your issue appears to be that each element in your list is unique but Bubble is not treating it as such. For example, items 8 and 56 are each a “sweater” but they are different sweaters. Bubble doesn’t (usually) allow duplicate values in a list. So though you are creating different TEXT values from the API call, you’re running into a problem later on when you try to manipulate that list (deleting values) and it’s only then, that Bubble is now seeing the duplicates.

I wrote “I may look into building this feature out in a different way” because sometimes, what you’re trying to do is actually an inefficient way of doing something. You usually discover this when you run into these types of problems. (I know I’ve had this happen to me hundreds of times!)

You need to somehow get your elements in the list to be its own DB record with its own unique ID. An example of your new data type:


To create a field that is a list of a data type will look like this:
image

Where you’ll run into problems is you don’t want to be making 200 API calls every second for every new record.

Thoughts?

Thanks for the extra info.

Yes, I had tried to get all 200 clothing items into their own DB record for a while but kept coming up short (other than api work flows which on my paid plan only are allowed once a month. Even at once a day I will have way more users than that for once a day to be a viable option). I had also tried creating a “do when condition is true” loop to convert the list of things into 200 individual records but found that after 5 rate limiting kicks in and only converts one item every 1.5 seconds (if I remember correctly) which also didn’t work.

So yes, I understand what you’re telling me to do now but given that I need to have 200 clothing items in my api response (the reason for needing that is too long to explain here), all options to make individual records doesn’t seem to be awesome (as you pointed out). I have tested out my appending of .a, .b., .c etc and it works perfectly as I own the api and can make that change on the back end. So I think I’m going to stick with that solution.
Thanks so much for your help