How to pull data into your app with a URL variable

November 2, 2021

You can use a URL variable to create a link to your app that automatically pulls data from a specific record in your database.


You have an app that pulls data out of your database. As usual, whenever you pull data out of your database you must build a mechanism in your app for determine which specific record to use in a single app session (i.e. which row to "look up"). The problem: You do not want the end-user to look up the specific record; you do not want to give the end-user a row selector question nor do you want to ask the end-user a question and then look up a record based on their response. Solution: Pass the value for looking up the specific record via a URL variable.

Here is a quick demo of what this looks like in practice:


Step 1: Create the URL variable

Inside the app that you want to pull data into, create a text type URL variable. You do this under Settings > Global configuration:

URL variables do not have values until you pass in a value via the app's URL (we'll get to this soon). Ultimately, your URL variable will have a value that is equal to the key from a record in your database (accordingly, I'm naming my URL variable `database_key`).

Step 2: Use your URL variable to index into your app's data source

Use your new URL variable in an expression block that indexes into your app's data source:

Great! As of right now, you have variables in your app for every column in your data source table. So, you can use these variables to create document templates, etc.

However, if you run your app you will notice that no data is being pulled in. This is because your URL variable (`database_key` in my example image above) is undefined, and this is because we have not yet created the app that generates a URL that passes a value into the URL variable. Let's do that next.

Step 3: Create a new app

The purpose of this app is pass a value to the URL variable of your original app. This app will be used by you.

In this new app, do the following:

  • Add your database table as a data source
  • Add a row selector question that allow you to select a record from that data source

Here is what my row selector question looks like:

Step 4: Create a URL for your original app

In this new app, add a URL logic block.

URL logic blocks require a base URL:

You're going to use the shareable link from your original app as the base URL. Note, this means you must activate your original app. After you do that, paste the shareable link into your URL block:

Now we're going to add a param to this base URL. When you add a param, you give it a name and a value. For the name, use the exact same name as the URL variable you created in your original app. For the value, use the key from the record that the row selector question "looks up" (the same row selector question we made at Step 3 above).

Your URL param should look something like this:

Step 5: Use this new URL

You now have a URL for your original app that passes a value to that original app's URL variable. Your final step is to somehow use this new URL. One way to use this URL is simply to paste it onto a page block so that you, the app user, can copy it and send it to your end-user. For example, like this:

All done!

Now, when the end-user clicks on this URL they will land inside your original app with a value that automatically pulls a particular record out of that app's data source.

Hire an Afterpattern expert

Go from idea to launch in weeks.

View services