Get record from app variable

Hi Appgyver,

I store my backend online database in an app variable when my app opens on the global canvas, this is to avoid the app loading the entire database on every page in the app.

I have an item list page showing data from the app variable but I can send the id to the next page so it knows what item was picked. It works fine with “get record” from the database backend when using the data variable but I can’t get it to work when trying to fetch the data / get a single record from the app variable.

Any suggestions?

Thanks Dan

Hi Dan! If you have a page that takes the ID of a record as a parameter, you can get an individual record from your list type app variable with the formula FIND_BY_KEY(appVars.records, "id", params.id)

Hi @Mari,

I have tried your suggestion and I do get a picture and text on the next page but it does not reflect the option you have chosen in the list item, it just gives me the same picture and text no matter what you pick.

Not sure if I am not sending the correct id or if it’s me not writing the formula correctly.

Hi Dan, if you are repeating the items on your list page, you should pass current.id as the parameter to the page that opens.

Hi @Mari,

Thank you so much for trying to help, I have done that but all I get in the validation is “object is not assignable to text / number type”.

Not sure what I am doing wrong since it was working when I was using a data variable as the source. :worried:

In which field do you get that error?

In formula and I am not getting a result any more.
This is my formula, the List Item page is sending current._id

FIND_BY_KEY(appVars.BrowseposterX, “Product_Name”, appVars.BrowseposterX[0]._id)

Hi, it’s likely because you are not taking the id from the parameter that you passed, but always from BrowseposterX[0]. So change that to params.id or whatever your page parameter is called :slight_smile:

For example if I had a fruit listing and a fruit detail page that takes the name of the fruit as its parameter, this is how I would access the name of the chosen fruit:

image

Thank you Mari, I think I am very close but just not quite there. I am not getting an error anymore :slightly_smiling_face: but still not getting any result coming up.

I have added the ._id to the end as I didn’t have that before. The page parameter is just called id and is set to accept all values.

Hi, maybe it’s that you should select by the _id field, not Product_Name if that’s what you’re passing?

Thank you Mari,

Yep that was it, now both a single picture and text are tracking through just fine. :grinning:

The only thing I struggle with now is I have a row of pictures repeated with
MAP, this is the formula I used to have:
MAP(data.BrowseposterX1.Scroll_Pictures,{id:item})

and the source:

https://BP.restdb.io/media/” + current.id

Not sure how change this so it reference with app variable instead.

Hmm, if you are repeating with appVars.BrowseposterX, “https://BP.restdb.io/media/” + current._id should work

Thanks Mari for all you help. Much appreciated. :+1:

1 Like

Hi @Mari,

I thought it was working but now I stopped using any data from the online database the row of pictures has stopped working, so don’t think I have done it correctly. :worried:

Okay, what do you mean by “stopped using any data from the online database”? What did you change and what did you expect to happen?

I have now switched over and only getting information from the app variable. Before, the page got information from a data variable set from the online database and the clientside database app variable. Now I am only using the app variable.

I am only having a problem with the scroll pictures(row of pictures), repeated with MAP everything else works fine.

Hard to say what might be the problem here :thinking: probably there is still some reference left to the data variable, or somehow the app variable is not populating correctly. If the row was working before, I don’t see why that would have been set up incorrectly.

This is what I had in repeat when it got the information from the data variable.

MAP(data.BrowseposterX1.Scroll_Pictures,{id:item})

https://browseposter-3.restdb.io/media/” + current.id

Okay, and how does your app variable look? How could you get the same id’s from there?

Hi Mari,

My app variable schema looks exactly like the schema set by the data variable linked to my external database. Now the row of pictures are getting the data from an app variable and not a data variable.

I have the same set up another place in the app, but this time the row of pictures are set by a clientside data variable and it works fine. I think the problem is when I am trying to get multible pictures stored together in the app variable in a repeat. Sorry not explaining it very well.