Get value from server table and put it in storage

Normally data is loaded into localStorage from the selected row of a screen table.

In my case. I am trying to put a value into localStorage from a field in the Server Table.

The server table is called Storage3 and the field is called Field1. There is only one row in Storage3. The value in Field1 is "Yes".

I am attempting to use the "Set Local Storage" feature in the Success element to do this.

In the proceeding code I have

select @mFIELD1:= Field1 from Storage03 LIMIT 1;

I then have Set Local Storage feature as per the screen capture below.

The result in the localStorage is shown in the second screen capture i.e. I don't get the value of row01, I get the name of the variable.

What am I missing?

Mike
pict1

pict2

Hi @mdsmith1,

I think you need to access the data from whatever is actually making the select statement. If that's a query called getData you'll be able to access it via something like getData.data.@mFIELD[0], though I'm not sure exactly how that will work with the user-defined value (@mFIELD) or why you'd even need it.
From the example you posted, you should be able to just change you query to SELECT Field1 from Storage03 LIMIT 1 and then access the value as getData.data.Field1[0]

I just can't get this to work.

Here is my data using CPANEL. Field1 = "Yes"

Here is my code in Retool

Here is my local storage form
pict3

Here is the resulting storage value in the debugger. It shows the name of the variable instead of the value of the variable.
pict4

Mike

Hi @mdsmith1,

Try this:

  1. Get rid of the @mFIELD1 line in your SQL, so your query in retool should just be select Field1 from Storage03 LIMIT 1
  2. I don't know the name of that query in retool, so I'm still going to refer to it as getData, but replace future references of getData with whatever name you've given that query in Retool.
  3. Change the "value" in your success handler to {{ getData.data.Field1[0] }}

If that's still not working, you can try setting the value in the handler to {{ getData.data }} so you can see the full structure of the returned value and then decide how to grab the data you want.

Mike:

It worked !!!

Thank you so much for helping me with this.

This is code I can use a lot and it was really important that I figure this out.

I have marked this as a Solution.

Thank you again.

Mike

1 Like