database

Pull data into an App

Updated: October 15, 2020

Pulling data into your App is how you allow the end-user to "look up" information in your database. The most common use-case for pulling data into an App is using previously collected data to quickly populate a document template.

Pulling data into your App is a two-step process: 

  1. Add a Data Source within the App Builder; and
  2. 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 Workbase table.

Add a Data Source

Any data that you want to pull into your App must be added as a Data Source under the Data Source tab of the App Builder:

Each data source is represented in your App 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.

Review of methods for "looking up" a row in your Data Source

When you add a database as a data source to your app, you have access to every row inside your database table. But how does the app know which row you want to use? Imagine your table contains client data: how does the app know which client to pull data about? 

There are four methods for determining how your app will "look up" a row of data from your database: 

Method 1: Row selector question: Provide the end-user with a search field with which they can "look up" a specific row of data (note: the end-user can only search through the key column of your table).

Method 2: Add app to database toolbar: Add the App to your database toolbar and you'll be able to look at your database table, click on a row, and use that row inside your app.

Method 3: Index into the database: Use a variable to "look up" a row from your database table. This variable can be defined by asking the end-user a question (e.g. "what is the client's name?").

Method 4: Query block: The most powerful method of finding a row. Allows end-user to "look up" a row using any column from the Data Source table.

Method 1: Row selector question

Use this method to allow the end-user of your App to find for a specific row in your Workbase by searching through the key column of your table.

This is what a Row selector question looks like when you run your app:

Note: this is not a dropdown; the end-user must begin typing in order to search

How it works

(1) Add a 'row selector' question to a question block; (2) select the data source you want to attach this question to; and (3) be sure to give your 'row selector' question variable a useful name.

Now, you have available inside your app a variable for each column in your database table. These new variables look like this:

Notice that these new variables combine your row selector question variable with the name of the columns in your database.

Method 2: Add app to database toolbar

You can add apps directly to the header of your database, known as the database toolbar:

Adding Apps to your database toolbar allows you to "look up" a row of data by simply clicking on that row and then selecting the app you want to use that data in.

This method is only appropriate if you want to give the end-user access to your database table (note: you can give end-users access to only some of your database data with portals and database connections).

How it works

Click the 'Add app to database toolbar' toggle.

That's it; you now have variables inside your app for each column inside your database table. Note: you must activate your app in order to see it in the database toolbar.

Method 3: Index into the database

You can use a variable to search through your Workbase for a matching row of data. You can only search through the database table's key column.

How it works

Indexing is accomplished with an Expression Block: (1) Add an Expression Block and select your database variable as the first component; (2) select 'index' as the operator; then (3) add the variable with which you want to search through the database table key column:

The variable you are using to index through the database table's key column can be supplied from many places, including:

  • Question Variable: Simply ask the end-user a question and use their response to index into the database.
  • URL Variable: Under the Settings -> Global Configuration tab, you can define URL Variables which can then be included as part of the URL you send to the enduser of the app. When they use that link, the app will already "know" what row to look up because the value would have been supplied by the URL itself.
  • Expression Variable: You could use an expression to combine answers from multiple questions (e.g. client name and date of birth) to define a variable that is then used to index into a table.
  • Client Portal Variable: If you build a client portal using Afterpattern's portals product, any time your client runs an app from their account a variable unique to that client (called the Portal_client_id) is passed into the app. You can use this value to automatically pull in data associated with that client from a linked database.

Method 4: Query Block

By far the most flexible and powerful method for "looking up" a row in your database table. A Query Block lets you "look up" a row in your database by searching through any column in your database table (whereas most other methods only allow you to search through the key column of your table).

Frequently Asked Questions

Don't see your question? Get support.
No items found.

Contact us for support

Talk to a real person, quickly. We're available 9am - 5pm EST.