Index into your database

June 15, 2021

What is indexing

Indexing is a method for "looking up" a row in your app's data source, if that data source is a table from the database in your Afterpattern project. Indexing allows you to find a row where the Key column equals a certain value. If you want to be able to a row where any column, not just the Key column, equals a certain value, use querying.

How does it work

To index into your database, you must first define a variable. This variable can come from many places, including:

  • Questions: 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 Blocks: You could use an Expression Block 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.
  • Portal_client_id variable: If this app is included in a portal, any time the end-user runs the app a variable unique to that user (called portal_cliend_id) is passed into the app. You can use this variable to automatically pull data associated with that user.

Once you have a variable, you can use it to index into your database with an Expression Block using the index operator:

Notice that your Expression Block is defining a variable. Give this variable a semantic name. This variable represents the selected row from your database, so a good name for this variable could be "selected_X" (e.g. selected_client).

What column does indexing search through

When you index into a database, you are searching through its key column:

How to use the data from the selected row

As soon as your finish setting up your index Expression Block, you will have access to variables for each column in your database table. These new variables are labeled using the Expression Block variable + column name:

You can use these new variables for anything you can use a normal variable for, such as creating document templates.

Hire an Afterpattern expert

Go from idea to launch in weeks.

View services