This is clear that you are clearing the contents of orderedList somewhere in your code. As long as orderedList contains what is already in the database key and new entries are added to it then once you save it, it will replace the existing list under the database key.
You are focusing on a single block of code that you are coping it in this post every time instead of logically following the changes to the list and see where you reset its contents.
Yes indeed, its very clear. Believe me I am really trying to follow the logic paths (as I understands it) the best I can…
I do only have two places in my code that handles the DB somehow, its two functions, one for “save” which is put in the “add-button-block”, and one for “sync with DB” which is put in the start-up-block.
That’s why you always see variants of these blocks
I am, at the moment, putting every action in labels to hopefully see what is happening and where the data gets removed.
Im getting close though…
As for now I have managed to add items and keep the old ones, but the issue now is that those old items gets to numbers after saving new item when restart.
Hi. I have rebuilt the app as I couldn’t find anywhere where my variable orderedList clear the contents of it. I have still the same problem though, but I have an idea…
Could it be that the data/info inside my “orderedList” are JSON? Cause that’s what’s coming out from Firebase’s Get-block, right?
I know for sure that my content from Firebase are in my variable, cause I have put in on a label to show the content and it is there -, and when “generate JSON from object” I can see it.
Could it be that I need to put it as list-content, for only my Items in this variable? Could that be the reason why it wipes out all the content in DB as soon as I add new stuff?
But if so, could someone please advice me how I can get that data from DB to be a simple list/array that I can put in my variable? I have tried many different ways to get this work and red through the Thunkable docs, but I am not able to get it work.
thanks a lot for any help!
here are the get-block which I need to put in my “orderedList” variable as a list/array (?)
And when you get it back from the database it will be a long text separated by commas. You can then use the make list from text block and convert it back to list.
This should solve your issue if you believe this is something related to the database itself.
Hi.
Thanks a lot for your tips. This worked for me and it confirmed my suspicions, that it was the JSON format that made my app crash/wiped out previous items in DB. At least that’s my understanding.
This is the thing:
by doing your way here I got content in my variable “orderedList” that looks something like this:
item 1, item 2, item 3. So, as I thought, when I press the save button and save new items to that list it will understand what to do.
By simply save the “orderedList” when save to DB, the value back from DB will be “object Object” if I simply ad the value to my “orderedList”. So to put it there I needed to ad the “generate JSON” block for that.Then it will look something like this:
[“item 1”, "item 2, “item 3”]… So this will crash my app when adding new stuff in here.
I do this for practice and I want to learn. I could simply go with this method that works, but then I will have all my items as a text string in DB. So, obviously I would prefer to save my “orderedList” so that I can get my items in DB as separate Items.
Is there any other way to formate the value from DB without having to generate a JSON from it? Or, should I formate the JSON with some filtering to get rid of all those characters? Whats common for you “professionals”? How would you have done? I have tried a ton of different possible solutions for this but to generate JSON or create text from list is so far the only luck I got…
Any tips or ideas would be much apprichated.
When you see [ and ] in JSON it means the content is a list. Treat it as a list in your app and add to it using the blocks in the list drawer. If you try to add to it like a text then you will overwrite the list.
You do not need to convert back and forth the values you receive from Firebase because you are receiving it already as objects and you can use the blocks in the object drawer to manage every aspect of it.
It works now, I simply set the variable “orderedList” to be the value from DB when start up the app. (I have tried this before many times but then the app has crashed for some reason, maybe there was something else there disturbing. But now it works and it will not wipe out anything after restart.
But this is depending on that the content in DB is my items only, but when I add a new item in a list I get this “scopeVariableInfo”-stuff in there as well and when that comes into my DB the result from the getBlock in my code will be “object Object” and then this whole process won’t work.
If I manually remove this “scopeVariableInfo” in my DB and restart my app it will work again.
I’ve actually changed to your solution as I think it’s much cleaner.
My I ask:
If I simply put the value on my variable when “get” I will get the same result in my label (for check) as if I put the “make list from-value”. But if I save my app will crash.
What is it making the app crash then even the output from “get” block for db is the same?
Is it that even if it looks the same my output will be a text because I have saved as a text?
Just want to understand.