True… Maybe someone will build both and report back
Perhaps I should rename it to Thing Index Finder lol - goes to check code of IndexOf SSA
True… Maybe someone will build both and report back
Perhaps I should rename it to Thing Index Finder lol - goes to check code of IndexOf SSA
@keith Bubble says I don’t have permission to view the code. My open source education has been thwarted!
You know… List Popper and Friends seems to have decided to make itself private, which I didn’t think was possible. I reset it back to open source and now it’s available again.
Dunno what’s up with that! You should be able to see it now.
So, I did build that: First just seeing what’s up when you have a backend workflow that Seaches for all Orders upon order creation so we could understand what happens. (What happens is complicated and messy and is not what one would naturally expect.)
The first thing that’s super interesting is that we forget that Do a Search for… is dynamic and, in fact, the values in and size of that list CAN change inside the workflow, even as it is proceeding. This surprises us, but it’s the source of @morgan’s (and others’) problem.
So when you’re spamming that create order button… Oh heck, it’s just easier to talk about.
So @eli, it DOES seem that it’s totally possible to do this w/o extra plugs, but it sure does take a lot of experimenting to come to that!
#lockdownandlearnwithkeith
Hey Keith, what a legend! I’m very impressed with your comprehensive solution and I’ve looked at the front and backend. It would be great to see a video of it in the most basic and simple form with the bare minimum (without the extra fields) I need to have a number go from PP-1000001 to PP-1000002 and so on.
Meanwhile, I did revert to a recursive workflow that is working reliably but definitely a strain on the server (which it should not be), even my ZX81 and commodore 64 could add 1+1 and so on quicker than Bubble’s server - performance really is a joke, I have to keep saying that until it’s properly addressed. @emmanuel?
Oh just saw this, thanks man!
You’re welcome. This was a really good question and I’m glad I finally experienced this for myself!
(In case it’s not clear, the best answer to this is briefly demonstrated at the end of my video. No external plugins required. But hey at least now you know about some of the cool features in List Popper and Friends for other use cases!)
ASIDE: the performance issue here has nothing to do with capabilities of the platform, it’s about the value for money. I don’t know how much cap you have to buy to get the experience you want, but my experience is that it’s more than you expect.)
I’m happy to donate to your karmaware Keith just for your assistance! It really is quite frustrating to get to a point in the development of a bubble application and find that something so seemingly simple is actually fraught with danger. I do not understand how such a basic function can be so difficult - it should be one of the essential functions built in to bubble (a reliable count of rows in a database at any instant).
Well, it’s just a quirk of the platform. It’s a really clever platform, but there are times when that cleverness leads to unexpected stuff.
The main issue I have is that, it’s an incomplete array-oriented environment. So, as with this specific issue, you have to test and then the easy, array-oriented option is not available and then you have to think REALLY laterally to come up with the solution.
Keith is the man!
Can you show us what that looks like?
I assume this isn’t idle curiosity …
The “one-liner” is a bit nasty, because it transforms Bubble’s list into a Javascript array, before it can do the indexOf operation, and it matches by unique id.
properties.thinglist1.get(0, properties.thinglist1.length()).map(x=>{return x.get("_id")}).indexOf(properties.thing1.get("_id"))
A working sample is at the bottom of this page: https://toolbox-example.bubbleapps.io/version-test/serverscript?debug_mode=true
Alternatively I could have a dynamic expression of unique ids and pass it in as part of the script, to make a simpler line of:
["mylist's unique id".join with "," ].indexOf("mybook's unique id")
Thanks for the example. I prefer having coded solutions for discrete needs instead of plugins. Thanks of course to your Toolbox plugin which has been like a rock in terms of reliability!
I am now just resisting this for another app I’m building and counting what’s in the list will not work if there are several orders being placed around the same time. As Keith has demonstrated you will end up with multiple records being assigned the same number.
Use List Shifter to add the numbers.
A WORD OF WARNING THAT SOME OF THE SOLUTIONS PEOPLE OFFERED ABOVE ARE NOT RELIABLE AND YOU MAY, IN FACT, GET DUPLICATES OR WORSE UNLESS YOU USE THE FOLLOWING METHOD AS - I HAVE TESTED THEM ALL JUST LIKE KEITH DID
Not knowing this caused me a lot of issues and setbacks so I hope it saves others. The solution that works perfectly and reliably in bubble natively is the solution buried at the end of Keith’s great video - and all the reasons are explained by him.
in summary the solution is:
Lets say you want unique, sequential order numbers that increment by 1
That’s it!
As I said, the reasons why this works (and nothing else does) is in Keith’s video if you want to know why.
Of course there are other solutions by using plugins that reference an external API but if you want a reliable, simple, native sequential order number then there you have it.
Oh my god! When first time I tried this, and knowing this method works reliably I was shocked!
You both just made my day! Thank you thank you and thank you! @keith @morgan
Am I correct to assume that if any records are deleted from the database it would be possible to have duplicate IDs?
Say I have 100 orders in the database now. The next order will be assigned ID #101
But if I now go and delete order with ID #3 from the database the next new order will be assigned order ID # 101 which will result in two orders with the same ID.
Is this correct?
Without giving it much thought, the answer is yes, probably. However, if it is orders you’re talking about I would have a status field that changes to “cancelled” or something like that so there is no chance of this.
Hello @morgan,
Nice one! Would you mind telling me how can you format the number to have 10 digits with a constant number that starts by “4” so the number will be “4000000001, 4000000002”, etc.