App Builder

Variables

Updated: September 7, 2021

Variables are a fundamental part of building automations. When you add a question to a page, you're creating a variable. When you build a document template, you're using variables to indicate how it should be auto-populated. When you send data to a database, you're sending variables.

Terminology

In order to talk about variables, you need to know 4 different terms: 

1. Name/label

A variable's name (or label) is its title. It's how you refer to it. Variables defined by a question come with a default name:

You should give your variables semantic names. Meaning, names that, if seen out-of-context, would give you a sufficient clue as to the type of data this variable represents. For example, user_name is a good variable name.

2. Datatype

There are many different types of data. For example, some data takes the form of text (like this sentence) while other data takes the form of a date (e.g. 06/26/1986). Every variable has a datatype.

3. Defined by...

This refers to how a variable is created. For example, you might say "the variable user_name is defined by a short text question." There are many ways to define a variable in the app builder, including:

4. Value

A variable's value is the specific piece of data it represents. Generally speaking, the purpose of a variable is to have many different potential values (you can create a variable that has one and only one value; this is known as an environmental variable). Some variables have a limited set of values (e.g. a boolean datatype variable is only either true or false), others can have nearly infinite potential values (e.g. a variable defined by a short text question will have a value of whatever the end-user types into the question field).

Types of variables

In Afterpattern, variables are categorized as either primitive or special.

  • Primitive: Variables with basic datatypes, e.g. plaintext, date, or boolean (true/false). These variables are common to all programming languages.
  • Special: These variables have a special purpose or special rules that govern how they operate. These variables include such things as unique IDs for portal users or lists of "data objects" created by loops or Query Blocks.
Primitive variable

Plain text

A simple, unstyled piece of text.

There are many ways to define a plain text variable. The most common is with a Short Text question. Other methods include:

  • Radio buttons question
  • Dropdown question

... and more.

What can you do with a plain text variable?

If start a logical expression with a plain text variable, you will see the plain text datatype operators (these operators are available to you anywhere you wish to manipulate a plain text variable): 

There are many operators for plain text variables, most have to do with formatting (e.g. join with a space to..., to uppercase, etc).

Primitive variable

Rich text

A styled chunk of text, including headers, bulleted/numbered lists, links, etc.

Rich text variables are defined with:

What kind of styles can you add? 

In addition to all the styles we give you a button for (headers, bold, etc), you can use markdown syntax to create a huge variety of styles.

Primitive variable

Number

A number (can include fractions).

The most common way to define a number variable is with one of the number-type questions.

What can you do with a number variable?

If start a logical expression with a number variable, you will see the number datatype operators (these operators are available to you anywhere you wish to manipulate a number variable): 

Most of these operators are for performing a mathematical calculation, e.g. adding to a number or comparing a number against another.

Primitive variable

Datetime

A fixed point in time. By default, datetime variables are formatted as "June 26, 2021" but you can change that under your app's settings. Datetime variables are defined by:

Note that you have available, in every app, special variables for Today and Now.

Primitive variable

Boolean

A boolean type variable has one of two possible values: true or false. Boolean variables are defined by:

If you're building an app with many logical expressions, you will likely use many boolean type variables. Booleans are a fundamental part of computer programming. Most of the logical expressions you'll create will resolve to boolean variables. For example, this long logical expression resolves to simple True or False (a boolean): 

Primitive variable

File/image

You can define file/image type variable with either an Upload File question or a by adding a column to your Afterpattern database of a type 'File'. A file/image variable is only every 1 file, i.e. app users can't upload multiple files to an Upload File question nor can you store multiple files in a file-type database column.

special variable

Today

The Today variable is equal to the day on which the app is run. This variable is automatically available inside every app; meaning, you can find the variable in any 'Add variable' dropdown or in the Expression Editor: 

special variable

Now

The Now variable is a more specific version of the Today variable (see above). The Now variable is equal to the day and time on which the app is run (the time is equal to the moment a new app session is started).

special variable

Session ID

A "session" is when an app is run. Every session generates a unique Session ID (a random and unique 32 character string). The Session ID variable has a consistent value throughout a single app session.

What can you do with Session ID? 

The Session ID is most useful as a key value when you send data to a database, like this:

Session ID vs. "Assign automatically"

The default key value when sending data to a database is "Assign automatically":

"Assign automatically" creates a random and unique 32 character string, just like Session ID. However, unlike Session ID, "Assign automatically" is not consistent throughout a single app session. Meaning, if you use "Assign automatically" 3x times in a single session, it will produce a different value each time:

... whereas if you use Session ID 3x times in a single session, it will produce the same value each time:

Why is this important? 

If you send data to a database and the key value you send is equal to an existing record's key value, the app will not create a new database record but will instead update that pre-existing record. Learn more about updating existing records in your database.

special variable

Portal client ID

If you create an Afterpattern portal, every user in that portal will have a unique Portal client ID; a random and unique 32 character string associated with that specific user. The Portal client ID variable is useful for sending data from your app to an Afterpattern database such that the data will be visible in your portal only to the user who created it. Learn more about creating database connection filters in your portal using Portal client ID.

special variable

Portal group ID

Portal group ID works the same way as Portal client ID (above) except that it can be shared by multiple users. This allows you to create groups of users who have access to the same data in your portal.

special variable

List

A list variable represents an array (a collection) of data. A list is made up of members and each member has one or more attributes.

This list has 3 members and their attributes are name, date of birth, and SSN:

There are two ways to create list variables:

  1. Loop section, which creates list members by allowing the end-user to repeat over a set of blocks (every time they "loop" over these blocks, they add another member to the list); and
  2. Query block, which pulls one or more rows out of your database; each row is a list member.

How do you use the data contained in a list variable? 

Before you can use the data contained in a list variable, you must provide instructions as to how that data should be organized. For example, imagine you want to use the name attribute of the above list, how should those names be organized? As a bulleted list? Or maybe in a comma delimited sentence? 

Check out our lesson on working with lists.

special variable

URL variable

A URL variable is simply a primitive variable that's defined in a unique manner: via the app's URL.

The most common way to define a variable is with a question. For example, a short text question defines a plaintext variable, and the value of that variable is whatever the end-user types into the short text question field.

If your app has a plaintext URL variable, you could use that variable just as you would use a plaintext variable defined by a question; the difference is that the URL variable's value is derived from the URL that led the end-user to your app.

Here is what an app URL looks like with URL variables in it:

The two variables are user-name and email, and their respective values, in this particular instance, are "Thomas Officer" and "thomas@afterpattern.com".

If you build an app with URL variables in it, you'll need to build a 2nd app that creates the URL that passes values into your 1st app's URL variables. This 2nd app will use the URL logic block to create such a URL.

How to create URL variables:

You create URL variables under Settings > Global configuration:

When you create a URL variable you determine its type (the only possibilities are plaintext, boolean, number, and date).

Use-case: Imagine you want to allow a client to update their own information in your database (Afterpattern or Clio). You have an app for collecting information and this app pulls data from your database, allowing the end-user to update their information specifically. The problem is that you don't want to give the end-user access to your entire database, only their information. What the end-user needs is the key value associated with their data; you can give them this key value by passing it through a URL variable.

On this page

Basics
Primitive variables
Special variables

Hire an Afterpattern expert

Go from idea to launch in weeks.

View services