Hi
I apologize in advance if this is not the right category. I just joined both this forum and developing with Retool and it's not clear to me which category this questions fits bests among those in the list of categories.
As for my question, here the details:
Goal: Writing an app that will collect configuration data for a building yet another app, albeit a mobile one. The config data will be input manually, yet it's a large amount. Thus users need to be able to "save" all data provided so far and "continue" next day.
I am building and will be running the app from an in-house self-managed Retool server.
In Retool I've seen the option to add an export event handler to a button and I tested it by downloading a full table. The output is great: csv, json,...
However, I don't know how to make it export the values of several different textInput boxes at once. This would be the "save" part I mentioned above.
Furthermore, It's unclear to me how could I import those values back into their corresponding textInput boxes (the "continue" part).
Are both things possible in Retool? Maybe only through transformers?
I would appreciate any help on this.
Thanks.
Cheers,
MA
Hi @MASL! Welcome to the community and thanks for reaching out.
Instead of exporting and importing data in the form of a local .csv or .json file, have you considered persisting your data to a database? That's where Retool really shines. Both approaches are possible within Retool and I'm happy to help with either, but I strongly recommend the database approach.
Assuming you've already configured a RetoolDB instance, you can start by creating a table that defines the schema for an individual app configuration.
Hi Darren,
thanks a lot for replying. Sorry, I didn't see your reply until now.
I also heard in the meantime about using a RetoolDB and it seems a more systematic approach.
My problem is that I don't see any RetoolDB resource available in our self-hosted Retoold server. I installed and set up a PostrgresqlDB in another instance and created a postgresql resource, but I understand you don't mean exactly/just this.
If I go to mydomain/resources?setupRetoolDB=1 I only see a list of resources, but under the "Retool managed" there is not RetoolDB, which I undertand you mean it should be?
Wrt to my initial alternative method, I know how to create a button, attach an event action and export the config data I want. But, how can I import the config data back into their corresponding text boxes?
No worries! The solution I'm proposing doesn't necessarily rely upon having a Retool managed database - any database will do the job - but it's still odd that you're not seeing that option. On self-hosted instances, the only real benefit of configuring RetoolDB is the nice UI. What version of Retool are you running?
The challenge with implementing your original idea is that files uploaded via any of our native components are all parsed as base64, meaning it would take a fair bit of additional processing in order to extract the raw data. One similar but more flexible idea is to write your config data to Google Sheets and then retrieve it when your app first loads.
Wherever you store the data, though, the pattern you'll want to use is roughly the same:
Write a query to retrieve the data that runs on initial app load
Define a Success handler on the query that populates your app's inputs using the fetched data - e.g. input1.setValue('newValue')
Ok, I finally opted for going with you initial suggestion of using a Postgresql backend. I can save the config data into the db and I can "read" it via a select.
There are however a couple of differences: (1) I cannot change the app, which just uses input text boxes, and (2) the requirement is to use a couple of button for "saving" (works like a charm) and "loading".
How can I "grab" the output of the "loading" select statement in javascript?
Once I get a hold of that, I guess it should be trivial to iterate through all columns and issue those "setValue" statements.
Thanks Darren, things are starting to make sense for me.
Where I am now is at figuring how to call that 'setValue'. In particular, I would like to iterate over the fetched data and automatically populate the right config value.
As. you can see from the screenshots, I got both steps working, i.e., I can read the data. But I am stuck at referencing the corresponding input objects. Their names are the same as the column names in the fetched data.
What I would like to do is something like what is suggested in that screenshot: k.setValue(data[k]).
Is that something that's possible in Retool?
Worse case scenario, I would have to hard-code the loading as well. Painful but doable.
Aha, I tried that before too. Alas, it failed with the error intro_customer_name is not defined. Here, "intro_customer_name" is the name of the input box I used for saving that config data.
Am I missing a more proper Retool way of doing this, or is my use case a bit off? I imagine that had they designed the whole app using forms, things might be easier now
Hmm it works on my end and should generally be a functional solution. Alternatively, if you're okay with a slightly more manual solution, you can set the Default value of every input to reference load.data.
You could also load the data into a table component and make the columns editable! It's not that your use case is particularly niche - I think it's actually general enough to not have a prescribed solution and can be implemented in any number of ways.