Data help - Copy list function

I have a three DBs:
‘Properties’, ‘Rooms’, ‘Items’.

‘Properties’ has a list field of type ‘Rooms’.
‘Rooms’ has a list field of type ‘Items’.
Specific ‘Rooms’ & ‘Items’ records are marked as ‘Default’: ‘Yes’.

When a user creates a new ‘Property’, the workflow uses the copy list function to do a search for ‘Default’: ‘Yes’ Rooms and create a new list.

The workflow then uses the change list function to change ‘Default’: ‘No’ for the new rooms.

That list is then set as the ‘Rooms’ list in the new Property.

All good so far! This workflow works well to create a new property with Room records that are unique from each othere.

However the ‘Items’ list attached to each of those new ‘Rooms’ are still the original ‘Default’: ‘Yes’. When an ‘Item’ in a Room is edited it changes across all Properties with that Room.

In the new property workflow, how can we also make a copy of each ‘Rooms’: ‘Items’ list and set it for each respective ‘Room’?

That took more text than I’d like to explain and I hope it makes sense. Any guidance would be a massive help to me!

Cheers! Adam

Hi there, @adamgraff89… I assume you used the concept in my reply on one of your other posts (I’m not sure, though, because you never replied to that post) to get unique rooms for each property. Well, the concept for items within a room would be the same. Look for items associated with a default room that is being copied, make a copy of those items, and associate the items with the newly-created room. Have you already tried to implement that concept and it’s not working?

Best…
Mike

Thanks Mike and yeah I used your advice, it was very helpful. Apologies for coming back to you on progress, perhaps this questions should have been part of that thread.

Anyhow, I followed your guidance and by using the copy list & change list I’m able to give each Property it’s own ‘Rooms’ list.

But at the same time I also need to iterate through each of those Rooms to do essentially the same thing with the ‘Items’ in each ‘Room’.

I can’t figure out how to do that in the workflow. When I use the copy list & update list approach, each ‘Room’ ends up having the same list of default items. Whereas each ‘Default Item’ can belong to only one or more Rooms.

Any ideas how to go that level deeper to achieve that?

Cheers,
Adam!

Without seeing your exact setup, it’s hard to know which way I might go. A thought that does come to mind, though, is potentially having a field that links a newly-created room to its default room. With that field in place, I’m thinking it would be easy to “access” the default items for a room’s associated default room, and then you could create new items and link them to the new room. Do you think something like that could work?

Yeah, the structure is hard to explain over text :sweat:

So let’s say I have a Property with a list of copied Default Rooms (so they’re unique). Each comes with the original Default Items.

If I had a field that linked the Unique Room to the Default, what function would you use to get a copy of each Default Rooms Items?

Appreciate you taking the time to help brother!

Perhaps a simpler way to ask the question is:

Imagine you have a list of THINGS and each of those THINGS contains a list of OTHER THINGS.

In a workflow, if I use the Copy a List function to copy the list of THINGS how do I also make a copy of the OTHER THINGS list at that same time.

Right now, when I make a copy of the list of THINGS, each item in that new list is linked to the original OTHER THING item. I need the new, unique list of THINGS to also contain and new, unique list of OTHER THINGS.

… maybe that makes it clearer but I’m not sure haha :sweat_smile:

Essentially, how do I copy a list of THINGS and its respective list of OTHER THINGS at the same time to create two lists of unique items.

Yup, I understand what you are trying to do… it’s just difficult to suggest a potential solution without working through it, so I am trying to create an example that mimics your use case.

After playing around with this one for the past half hour or so, I am pretty convinced that you won’t be able to use the Copy a list of things workflow event to do what you are trying to do. You will need to use a (or maybe multiple) recursive, backend workflow(s) so you can loop through the creation of the rooms and items one at a time in order to be able to make the associated links between the things as they are created.

Yeah I’m also realising this, but I surely can’t be the first to navigate this issue. Seems like it would come up a lot in apps etc.

An idea that may work I just can’t seem to figure out the setup of Step 3, could be…

Using the copy/make changes to list functions:

  1. Create a new unique THINGS list with the OTHER THINGS list cleared.
  2. Create a new unique OTHER THINGS list.
  3. Using the make changes to a thing… function on the new THINGS list, go through each item: to update it depending on search parameters.

I can’t quite get my head around how I would setup Step 3 (or if it’s even possible?). Do you think it’s possible? It’s melting my brain trying to think about how to set it up :sweat_smile:

Yup, I tried to do exactly what you described, and no, I don’t think it’s possible… well, not by copying and making changes to lists of things, that is. You are definitely not the first to do something like this, though, and the way I would go about it is the way I have already suggested… a recursive, backend workflow.

1 Like

Okay cool. I’ve not used that aspect of Bubble before so I’ll tackle it. Do you have any references/guides you can remember that may help guide me on this?

Cheers!!

I could point you to a number of resources (and I am sure you could find those resources yourself by searching, which I would encourage you to do), but I think it would be tough to make the leap from those resources to what I think you are going to need to implement. That being said, I created an example that is specific to your use case, so walk through it and see if it makes sense. Full disclosure, though… the sandbox app I used to create the example is on the free plan, so I have not actually tested what I am about to show you. I believe it should work, but you never know until you try it, and I will leave that to you.

First, go to your app’s Settings >> API tab and check the box next to Enable Workflow API and backend workflows. Next, click the page dropdown in the upper left-hand corner of the editor and select Backend workflows.

My example has two backend workflows. One of those workflows creates the rooms.

The other workflow creates the items.

When a new property is created, a workflow runs that creates the property and then schedules the backend workflow that creates the rooms.

The first step in the create rooms backend workflow creates a new room.

The second step makes changes to the newly-created property.

The third step schedules the backend workflow that creates the newly-created room’s items.

The fourth step schedules the create rooms workflow again until there are no more rooms to create.

The first step of the create items backend workflow creates a new item.

The second step makes changes to the associated room.

The third step schedules the create items workflow again until there are no more items to create for the associated room.

As I said, I didn’t test this stuff, so I could easily be missing something that causes it to fail catastrophically, and you might have to play around with the timing of the scheduled workflows, too (maybe schedule them a certain number of seconds or minutes apart). It all seems to make sense in my head, though, and I hope it helps you get down a good path.

1 Like

Maaaan, my head was fried yesterday trying to apply the guides I could find to my use case and so your guidance here is so so so appreciated! I will implement and report back…

Thanks a lot my friend!

1 Like

This worked like a charm :star_struck:

I still have so much to learn with Bubble and this was a big one. You really saved a lot of time with your help. I appreciate it a lot my friend!

1 Like