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.
In order to talk about variables, you need to know 4 different terms:
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.
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.
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:
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).
In Afterpattern, variables are categorized as either primitive or special.
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:
... and more.
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).
A styled chunk of text, including headers, bulleted/numbered lists, links, etc.
Rich text variables are defined with:
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.
A number (can include fractions).
The most common way to define a number variable is with one of the number-type questions.
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.
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.
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):
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.
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:
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).
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.
The Session ID is most useful as a key value when you send data to a database, like this:
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.
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.
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.
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:
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.
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.
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.