app builder

Logic Blocks

Updated: September 8, 2021

Logic Blocks make up the invisible "back end" of your app. They create variables whose values are logical expressions, blocks of text, conditional statements, or lists.

It's possible to build a relatively simple app with zero Logic Blocks, but you'll likely need Logic Blocks for more advanced apps.

How to create

To add a Logic Block, click "Add logic" under the Blocks tab of the App Builder:

Logic blocks are invisible to the end-user, so it does not matter where you place them in your list blocks.

Expression block

The expression block creates a variable that is equal to a logical expression.

The variable able to vote is True if the number of years between Today and date_of_birth is greater than or equal to 18

Text block

The text blocks creates a richtext datatype variable. For example, this text variable creates a block of text that represents a clause that may or may not be inserted in a document template: 

Encapsulating text in variables is an essential part of building a document automation app, because this is how you conditionally add text to a document template.

Text Variables and document automation

In our Afterpattern 101 Tutorial, you learn how to build a document automation app. Jump to the 'Intro to document automation' video to see how Text Variables are used to conditionally add text to a document.

Conditional block

The conditional block allows you to create a variable that has the value of one of a pre-determined set of variables or pieces of text (i.e. strings).

For example, imagine you want to create a template invoice where the price changes depending on what service the end-user selected:

This price, encapsulated in the variable price_for_document, can have one of three possible values as determined by your Conditional:

What is happening in the above Conditional:

  • If the service requested is "copyright claim", use price_1; else
  • If the service requested is "ip investigation", use price_2; else
  • Use price_3
What does the "else" statement do? 

In this example, there are only 3 possible services the end-user can request. This means, after we define the price for two services, we can simply instruct the conditional to "fall back" on price_3 if neither of these two services is requested.

Does the datatype of the variables assigned matter? 

Yes. The potential values for the conditionally defined variable must all share a data type:


Short text and long text are different data types

Variables defined by short text questions create plaintext type data, whereas variables created by long text questions or Text Blocks create richtext type data. Use this workaround if you want your conditionally defined variable to have potential values of both plaintext and richtext type variables.

URL block

The URL block allows you to construct a URL. You begin with a base URL (e.g. mywebsite.com) and then add params (or parameters). Each param includes a name and value. For the param value, you can assign variables: 

By assigning variables to your URL param values you can create URLs that are unique to the end-user. These URLs can then be used in a redirect block to send the end-user to a new website and, more importantly, pass information along to that website (the information contained in the variables used for param values).

Query block

The query block allows you to compose a filter and then pull all matching rows of data out of one of your app's data sources. The query block creates a list datatype variable:

This variable is a list of all matching rows from your data source.

How to use query blocks

  1. Add a data source to your app;
  2. In your query block, select your data source;
  3. Compose a filter.

How to use list data

A query block creates a list of all matching rows. Before you can use the data contained in these rows you must first provide instructions for how that data should be organized. Check out our lesson working with lists.

Sort block

The sort block allows you to reorganize a list (i.e. sort a list). The sort block creates a list datatype variable:

How to use sort blocks

Prerequisite: You must have a list variable in your app. Lists are created with either a loop section or query block.

  1. In your sort block, select the list you want to sort;
  2. Compose a logical expression for sorting;
  3. Select sort direction (e.g. ascending or descending).

How to compose a logical expression for sorting

Although you can write complex logical expressions, in most circumstances all you will need to do is pick a variable from your list. For example, imagine I have a list of children and for each child I have their name and date of birth. If I select the date of birth variable in my expression and then sort in ascending direction, I will create a list where the children are sorted from youngest to eldest.

How to use list data

A sort block creates a list. That list includes every member of the list selected in your sort block, just sorted according to your logical expression. Before you can use the data contained in these list members, you must provide instructions for how that data should be organized. Check out our lesson on working with lists.

Filter block

The filter block allows you to filter a list. The filter block creates a list datatype variable:

How to use filter blocks

Prerequisite: You must have a list variable in your app. Lists are created with either a loop section or query block.

  1. In your filter block, select the list you want to filter;
  2. Compose a logical expression for filtering.

How to use list data

A filter block creates a list. Before you can use the data contained in this list, you must provide instructions for how that data should be organized. Check out our lesson on working with lists.

List text

The list text block is one of three methods for organizing list data.

A list text block allows you to organize list data into a chunk of text. When you use the list text variable (e.g. by placing it on a document template), that chunk of text is repeated X number of time, where X is equal to the number of members in your list.

Check out lesson on working with lists for more guidance on how to use list text blocks.

List expression

The list expression block is one of three methods for organizing list data.

A list expression allows you to perform a logical function across every member of a list. Imagine you have a list of children, and for each child you have their name and date of birth. You can use a list expression to determine whether any of these children are born earlier than a qualifying date:

The purpose of the expression block is to arrive at a single value (in the example above, that single value is either True or False).

Check out lesson on working with lists for more guidance on how to use list expression blocks.

List transform

WIP

On this page

Basics
types of logic blocks

Hire an Afterpattern expert

Go from idea to launch in weeks.

View services