Issue passing data out of a table into a label

Hey All, sorry for the noob question, but I have been banging my head against this for a while:

What I’m trying to do:
Pass text data out of a data table to a label field following a user input form. The longer goal is to create a table of user inputs that can be put into a templated form as a pdf. But currently I am stuck on the “get the data out” part

What I’ve tried and what’s not working:
I can get the data from the input form into the data table, but trying data bindings and self.name.text hasn’t worked.

I have tried simplifying my data input into a test project with 1 input field and 1 output field. I would appreciate some guidance.

Clone link:
https://anvil.works/build#clone:OS462U2IKZOYW3IV=22XOP7QDKQKFUYDLTT43IKPO

Hello and welcome.

Could you share the server code that you are using to get the data back to the client as well as the code that you are using in the client (and the error if there is one)?

I’m on my phone so the clone won’t help me but I’m sure the code would.

Hi Campopianoa thanks for helping out, here is my server code to load and search the data table

@anvil.server.callable
def new_task(fname):
app_tables.data.add_row(fname=fname)

@anvil.server.callable
def get_name():
return app_tables.data.search()

Okay, how about the client code where you are trying to set the text property of the text box?

You will have to call get_name in the client and pass its values to the components that need them.

I was trying something along these lines on the report form:

def init(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.label_1.items = anvil.server.call(‘get_name’)

I don’t belive I saw that in your app. Perhaps I missed it.

The text on a text component can be set with:
self.label_1.text=“your_text”

Once you have your data, if you want to pass it to another form using “open_form”, you can do:

open_form(“your_form”, foo)

That passes foo to the init function of “your_form”. You can get it out of the properties argument in the init (or change the function signature to accept an argument).

as opposed to passing it from one form to another, is there a way to call the value from the data table?

so for this app the apptable is ‘data’ with only 1 column fname

so would it be:
self.label_1.text=app_tables.data.get(‘fname’)

Yes you can do that if you want the client side to have direct access to the database (read the docs on datatables to learn how). For security reasons, it is far more common to pull data from the datatables through dedicated functions.

1 Like

Hi not sure if Im doing the right thing by reviving this topic, but I am because I stumbled across it while looking for how to populate label text from the database. We need to do this a lot in Canada because Canada is officially bilingual – English and French.

So here’s a clone you can try out. Note, I have also included Hindi to show that you can also do this with multiple scripts. Feel free to use my clone.

https://anvil.works/build#clone:ZEK3DPOOQJ7IXK5B=7Z3UXRVLVYWU5QJBOU5IACIV