Pull data into an App
Pulling data is how you allow the end-user of the app to "look up" information in your database. The most common use-case for pulling data into an app is using that data to populate a document template.
Pulling data into your app is a two-step process:
- Add a data source; and
- Specify how you want your app to "look up" a row of data within that data source.
There are four methods for accomplishing step 2 (detailed below), but regardless of the method you choose the end result is the same: you create variables inside your app for each column in your database.
Step 1: Add a data source
A data source is where your app pulls data from. Add a data source under the Data Sources tab of the app builder:
Add a "Database" data source if you want to pull data from the Afterpattern database associated with the project that your app is in.
After you add a data source to your app, it will be listed under the Data Sources tab. You will notice that the data source is represented as a variable. As always, it's a good idea to rename the variable's label to something that makes sense in context (e.g. "client_data"):
That's it for Step 1. Next, you need to specify how you want your App to "look up" a row of data in this Data Source.
Step 2: How to "look up" a row in the data source
There are 4 different ways to "look up" a row in your data source, each designed for a different use-case. These questions will help you understand your use-case:
Will the end-user be able to view the database?
There are two situations where the end-user will be able to view the database this app is pulling from:
- You are the end-user; or
- The app is in a portal that exposes the end-user's data to them.
For this use-case, you can "look up" a row in the data source by attaching the app to the database toolbar.
Do you want to allow the end-user to "look up" any row in the database?
You can provide the end-user with a search field that allows them to find any row in the database:
Do you want to ask the end-user a question and then "look up" a row(s) based on their response?
You can ask the end-user a question (e.g. "what is the name of your employer?") and then you can "look up" one or more rows that match their response.
If you want to "look up" a row by searching through the key column of the database, use an index expression:
If you want to "look up" a row using any column of your database, use a Query Block. Note, this will return a list of all matching rows. There is an extra step required when working with lists (organize the list data with list text blocks).