Lesson Topics
database
Pull data into an app
If your app is part of a project, it call pull data from that project's database. This lesson will teach you how. Other lessons can teach you how to pull data out of Clio or Google Sheets.
Basic
Summary of pulling data
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 information in your database to populate a document template.
How it works
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 specific record(s) within that data source.
There are four methods for accomplishing step 2 (see 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.
Data source
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"):

Next, you need to specify how you want your App to "look up" a row of data in this Data Source.
Data source
Why you need to "look up" a row
When you add a data source to your app, the data source variable represents every record (i.e. every row) from the associated database table:

Before you can use this data in your app (e.g. to create a document template), you must build a "look up" method — this is how the app determines which record(s) of data to use in a single session (when you run your app, that is called a "session").
"Look up" methods
Summary of "look up" methods
There are 4 methods to "look up" a record(s) in your data source, each appropriate for a different use-case. These questions will help you understand which method to use:
Will the end-user be able to view the database?
Method: Attach app to database toolbar.
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 includes the data source as a database connection.
Do you want to allow the end-user to "look up" any row in the database?
Method: Row selector question.
A row selector question allows the app end-user to search through and select any record from your database. Only use this method if you're comfortable exposing your entire database to the end-user.
Do you want to ask the end-user a question and then "look up" a row(s) based on their response?
Methods: Index into the database or query the database.
These methods allow you to 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.
Use the index method if you want to "look up" a record by searching through the key column of your database.
Use the query method if you want to "look up" a record by searching through any column of your database. The query method will return a list of all matching rows.