After trying to add numbers to a list of numbers and not getting the expected result, I found out the “add list” won’t add values that already exist.
List A = [1,2,3]
List B = [2,3]
- Expected Result: List A : add list List B = [1,2,3,2,3] *
- Actual Result: add list List B = [1,2,3] (because 2 and 3 already are values in the list)
- How do I get add to the list another list without excluding duplicates?
- I don’t understand why this is the default behavior and why that action would be called “adding” (but that’s a question for the Bubble team.
What’s the Bubbly way?
*(This is the usual expected behavior in most programming languages with array.append(stuff) or similar)
Bubble does not allow dupes in a list of things. The only way to achieve what you are looking for is to create a separate type and then add individual records to the new type.
As far as I can tell:
I can create an object with duplicate values using the add button in the app data editor.
I can create an object with a workflow and set a list that includes duplicates using set list.
Based on that, we can conclude Bubble does allow duplicates. However the “add list” behaves like a “merge list” rather than simply appending new data in the array.
Since the “add” button in the data editor allows adding any number to an array without considering duplicates, why doesn’t the workflow function “add list” or “add”?
I find the idea of creating a new data object called “numbers” each time I need to add a number to an array a little absurd. Surely I’m not the first guy trying to append numbers to an array, right?
Is there really no way to just replicate the “add” function in a workflow?
Well that’s new to me. Thanks for the update and the learning.
In that case have you tried doing something like this:
Step 1: Set a custom state to the current value’s numbers of the array.
Step 2: Set the custom state to its current value’s numbers
append the additional numbers.
Step 3: Delete the value.
Step 4: Create a new value with the custom state.
Sounds interesting. Though I’m handling this on a backend workflow during a database trigger event.
So I don’t think I can access custom states because I don’t have access to any element.
Ah, I see. But the same possibility may exist using a workflow parameter and subsequent steps in your BEWF to manipulate the parameter. Just a reminder though that I have no idea if this will even work using custom states or the WF parameter, just brainstorming possibilities now that I’m aware Bubble takes dupes… just not easily
Is there any way to convert strings to lists and vice versa?
Sorry not that I have done.
Late reply. “Join With” gets you from a list to a concatenated string. In order to get from a string to list, you’ll need to do “extract with regex” which automatically spits out its Regex groups into list form.
EDIT: so for your specific case, store the “array” as a string. As new numbers are added, convert them to a string via “number_list:join with ,” then forge the new string. When retrieving back to number list, execute “Extract with Regex” with expression
then :format as number
This topic was automatically closed after 70 days. New replies are no longer allowed.