Last updated: Oct 24, 2019
20 minute read
If you know what data you want to add to a document, you shouldn’t re-enter it for each draft. It is far more efficient to enter it once into a table, and then pull the data out on an as-needed basis for each document. This tutorial will show you how to build a Legal App that does exactly that.
To showcase how this feature works, we’re going to build an app that allows someone to download a (fake) personalized summary of the 1920s era alcohol prohibition laws for a particular state.
Your app can pull in data from various data sources, such as Clio, Google Sheets, or a plain old table. To add a new data source, go to the Data Sources tab.
For this app, we’re going to add a Table:
Note: if you already have a spreadsheet of all the data you need, you can create a table of that data by clicking “CSV Upload”.
Each one of your data sources is represented as a variable. Initially, this variable will have a generic name (e.g. “table_1”).
Name your data source variable the plural form of whatever data it contains. For example, the table in this tutorial contains info for each state, so I will name the table `list_of_states`.
Click “edit” to start adding data to this table.
Your table will begin empty. Let’s add three columns and two rows. Let’s name the column headers ‘State’, ‘Is alcohol prohibited?’, and ‘Date of prohibition’. Then let’s start adding in our (fake) data:
Notice how it appears that our table includes three different types of data: text (or “strings”), true/false statements (or “booleans”), and dates. However, this is not the case: every piece of data in your table is a string. This will become significant as we seek to automate our document and want to perform boolean functions (e.g., ‘is this true?’) and date functions (e.g. how many years since this date?) on our data.
Let’s fast forward — I have now entered new rows for the reminaing 48 states and territories. I have also added a new column labeled ‘Plain text summary of policy.’ Under this new column I have added (fake) descriptions of the prohibition laws for that particular state:
Now that we have our data, we want to allow the end-user of this app to select a specific state (i.e. row) from the table. This is how the app will know which state to assemble the Prohibition Guidelines for.
The mechanism by which the end-user can select a specific row from the table is a Data Source Selector question.
You can add a Data Source Selector question to a Question Page Block:
After you add a Data Source Selector question, you need to specific which data source you want this question to pertain to (as your app may have multiple data sources).
Name your Data Source Selector variable the singular form of whatever data the associated data source contains. For example, the table in this tutorial contains info for each state, so I will name this Data Source Selector variable ‘state_selected’.
The Data Source Selector question will present the end-use with a dropdown that lists all the items from the first column in your table (see below). This is why the first column in your table includes a key icon: this column represents the means by which a user decides which row to use (i.e. it is the “key” to the table).
Now that you have a Data Source Selector question and you have properly identified which data source the question pertains to, you can reference the variables inherent to your table. For example, you can create a document template (under the Templates tab) and add a variable that represents a state name:
In the above example, you may notice that the variables have an interesting format: `state_selected: State`. These variables are created by combining your Data Source Selector variable with the column header from the associated data source. When the end-user selects a state from the Data Source Selector they are instructing the app to go look at a specific row of the data source table. Having identified a row, the app is then able to supply definitions for variables like
state_selected: State by pairing the selected row with a specific column (in this instance, the column labeled ‘State’).
You can quickly create new variables for your document template by clicking “create new variable” in the right-hand column of the Word Editor. For example, I may want to conditionally add one of two sentences to my Prohibition Guideline document: (1) Alcohol is prohibited in this state; or (2) Alcohol is not prohibited in this state, i.e. you can drink alcohol. Let’s do exactly that. We can call this variable
We define this variable as the following sentence: “Alcohol is prohibited in
Next, we can toggle ‘Conditionally insert’ to establish exactly when we want to add this sentence to our document. After we click this toggle, we click “edit expression” to open our Expression Editor. Now we can write our logical rule:
state_selected: Is alcohol prohibited?
This logical rule instructs the app to insert the sentence “Alcohol is prohibited…” only if, in the row for the state selected by the end-user, the column labeled ‘Is alcohol allowed?’ includes the string “True”.
The second dropdown in our Expression Editor allows us to select a data operator (operators allow you to manipulate data). The operator “equals” is a string operator. In this instance, we are using a string operator to check if the data in cell identified in the first dropdown is the four letter word “True”. Accordingly, it is essential to properly spell this word in these cells.
After instructing the app when we want to insert the sentence “Alcohol is prohibited…”, we can specify a backup sentence to use if the condition is not satisfied. We do this by adding a sentence to the bottom-most text editor (this is known as the "else condition"):
We can wrap up this template by adding two more variables from our table:
state_selected: Date of prohibition. Let's conditionally insert this variable (because there is no need to add this variable if the state selected does not prohibit alcohol), and let's leave the 'else condition' empty.
state_selected: Plain text summary of policy
This is the final step: We need to attach our template to a block in order to give it to the end-user.
You can attach a template to any block that does not collect data being used in the template. Currently, our app only has one Question Block. Since this block is being used to collect data for the template, we need to add one more block. This will be the end of the app, so let's add a Final Block and select our template from the 'Document' dropdown:
And that's it! You've just created an app that automates a document by pulling data out of a table. The blocks of your finished app should look like this:
© Community.lawyer, PBC 2019