Find specific item in list Firebase

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 :slight_smile:

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. :man_facepalming:

Thanks a lot for all your help both of you! :pray:

1 Like

This is the third time I tell you to look for places you use orderedList not the blocks you keep copying in the post.

To Night I will sit with this again…
I will have deep look then! Thanks!

1 Like

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 (?)

(now the variable has this “generate JSON from object”-block there just so that I am sure that it really contains what I want.)

1 Like

One way to eliminate complexity is

When you are saving your list to the DB, save it as text like this

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.

Thanks, great idea! I will try that out!
I am not sure if this will solve the main issue but it’s definitely worth a try :slight_smile:
Thanks again!

1 Like

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.

Thanks!

1 Like

That’s good news.

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.

Happy Thunking!

Hi.

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 remember you said that you had some workaround for this “scopeVariableInfo…”??

Thanks
/A

Hi muneer. May I ask, did you had some workaround for that scopeVariableInfo”-stuff?
I remember you said that you had a wile ago…??

Thanks!

1 Like

One easy solution is set it to null and it will disappear.

Set what to null?
scopeVariableInfo? Can I access that inside Thunkable?

1 Like

User_ID/items/_scopeVariableInfo

Set it to null and it will disappear.

Ok great, awesome! Thanks! I will try tonight!

1 Like

I just wanted to say thanks! This worked well for me!
This is how I did:

Maybe the would be some even more smooth way doing it but this works :+1:t3:

Thanks Muneer

1 Like

Welcome. Glad to see it working for you.

1 Like

This is my solution to the problem. In a clean manner

I made this simple data
image
This is the screen. When I press Get List I get the list in the screen
image

This is the code that runs

I can add to the list using this code

And I can save the list back to the database using this code

It will always be clear and without the annoying __scopevariableInfo

Thanks for this!! This looks so much cleaner then my project! I will try it out t night! Great learning! Thanks for this! :pray:

1 Like

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.

This will work great:


This will look the same in the label but crash the app:

Thanks

/Andreas

1 Like