Sample Exercise for Scripting Advanced Logic Statements

Scripting Advanced Logic in A2J Author


This exercise will teach you how to script five conditions or advanced logic statements in an A2J Guided Interview. This exercise does not contain an A2J Template or HotDocs Template component. It is meant to focus on the interview only.


The five conditions that we will be scripting will be contained in a simple A2J Guided Interview. The conditions are:

  1. Testing a user’s date of birth to see if they are over 18 years old.

  2. Creating multiple conditions in 1 question to set values to variables and branch the end user to different subsequent questions based on their answer to an income question

  3. Branching an end user to a specific question if they only have 1 person in their household.

  4. Testing the variable User Gender to determine if a question about pregnancy should be asked.

  5. Setting a value to a variable based on whether the user has 1 or multiple children.


The final A2J Guided Interview will look like this:


This Sample Exercise should be used by authors who have completed a basic A2J Author training. Training videos can be found on our A2J Author YouTube Channel (


  1. Log into your account. If you aren’t sure how to create an account, check out this resource.

  2. Once logged in, go to the “Author” tab and click it.  

  3. Then click “Run A2J Author”.

  4. A2J Author will open on the “Interviews” Tab. Under “Create a new interview” double click on “Blank Interview”. This will open up a blank A2J Guided Interview.

  5. Go to the “About” Tab and rename the title of the interview to Sample Exercise: Scripting Advanced Logic

  6. You will need to create several variables to be used in the A2J Guided Interview. Go to the Variables Tab and create the following variables. The variable type will be next to the variable name in parenthesis.

    1. Child or children TE (text)

    2. Client birthdate DA (date)

    3. Client legal issue TE (text)

    4. Income NU (number)

    5. Income too high TF (true/false)

    6. Number child NU (number)

    7. People in household NU (number)

    8. Pregnant TF (true/false)

  7. Go to the “Steps” tab. By default a blank A2J Guided Interview comes with 4 steps. Rename them as follows:

    1. Step 0: Welcome

    2. Step 1: Your Information

    3. Step 2: Do You Qualify

    4. Step 3: Exit

  8. Now let’s start creating the questions we’ll build our interview out of. Go to the “Pages” Tab. By default, an A2J Guided Interview comes pre-populated with 4 questions - 3 in Step 0 and 1 in Step 1. Also, Steps only appear on the Pages Tab when they have questions inside them. So when you first go to the Pages Tab, all you’ll see is Step 0 and Step 1. As we add questions to the other Step, it’ll appear. We will need a total of 9 questions for this Sample Exercise.

    1. Create 5 new questions by clicking the “New Page” icon 5 times. All the new questions should appear in Step 0.

  1. Double click on 1-Introduction. Change the page name to 1-Welcome. Create a 4th field. There should already be three fields to collect the user’s first, middle, and last names.

    1. The 4th field should be Gender. The label should be Gender: and the Variable should be User Gender.

  2. Double click on 3-Gender. Change the Step to Step 1. Change the page name to 2-DOB (Condition AFTER). In the notes field, type in “AGE function converts date of birth to age in years. This condition says if the user is less than 18 years old, then exit them.”

    1. Question text: What is your date of birth?

    2. Scroll down to the fields section. Create one field.

      1. Type: Date MM/DD/YYYY

      2. Label: Birthdate

      3. Variable: Client DOB DA

      4. Make sure the box next to “Required” is checked (because we wouldn’t want a user to skip a qualifying question).

  3. Before we can script the logic that branches an end user who is younger than 18 years out of the interview, we need to create the question the disqualified user will land on which explains what is happening to them. Double click on one of the newly created questions.

    1. Move it to Step 3.

    2. Rename it O-Do Not Qualify and Exit

    3. Question text: Sorry, but you do not qualify to use this program. Please hit the “Exit” button to close this program.

    4. Scroll down to the Buttons section. Rename the button label to Exit. Set the Destination to [Exit - User does not qualify]. This will trigger a new field where you can set a redirect URL for the end user. Enter or whatever website you’d like. If you didn’t include a URL, a message would appear when the user clicked the “Exit” button telling them to close their browser.

  4. Go back to 2-DOB (Condition AFTER) and double click to reopen it. Scroll down to the Advanced Logic section. In the AFTER logic box, type:


IF AGE([Client DOB DA])<18

GOTO “O-Do Not Qualify and Exit”



  1. Double click on 1-Question 1. Move it to Step 2. Rename it 1-Income (Multiple Conditions)

    1. Notes: #1 sets [Income too high TF] variable for later use and determines if income is too high, then exits user. # 2 Determines if income is in a middle, gray area, then directs the user to an extra question to find out how many people are in their household.

    2. Question text: %%[Client first name TE]%%, what was your household income for the last tax year?

      1. (The %%[Client first name TE]%% part is called a variable macro. It calls out the value of the variable inside the double percent signs. In this case, it will display the client’s first name as they have entered it when asking this question).

    3. Learn more prompt (the thought the end user avatar has): What counts as household income?

    4. Help: You should include any money earned or benefits received by any person living in your house.

    5. Create 1 field. Type: Number Dollar; no label (A2J Author will automatically insert a $ symbol); Variable: Income NU; check the “Required” box and check the “Show Calculator” box.  

  2. Before we can create the logic for 1-Income, we need to create the question that the end user will be branched to if their income is too high to automatically qualify for our assistance, but not too high to automatically exclude them. In our scenario, users who make over $35,000 a year are over our income threshold. Users who make between $34,999 and $25,001 are asked a follow up question. Anyone making under $25,000 automatically qualifies for our assistance.

    1. Double click on one of the new questions. Move it to Step 2. Rename it 1b-Income.

    2. Now close that question and reopen 1-Income (Multiple Conditions).

    3. Scroll down to the Advanced Logic section and type the following into the AFTER box:


IF [Income NU] >35000

SET [Income too high TF] TO TRUE

GOTO “0-Do Not Qualify and Exit”

SET [Income too high TF] TO FALSE


IF [Income NU] <35000 and [Income NU] >25000

GOTO “1b-Income”



  1. Reopen “1b-Income”.

    1. Notes: Question only appears in the user’s branch if their income is in the middle gray area between $34,999 and $25,001. If in this gray area and the user has more than one person in their household, they will be allowed to continue as they fit our income requirements. If they are a single person household in that income range, they will be moved out of the interview for not qualifying.

    2. Question text: How many people live in your household?

    3. Create 1 field. Type: Number (Pick from list); no label; Variable: People in household NU; check the “Required” box; Min value: 1; Max value: 10 (We are limiting the number of possible people in a household to 10 here arbitrarily. This would normally be set by the organization’s internal requirements.)

    4. Advanced Logic: (This will test how many people are in the end user’s household and if only 1, send them to the Do Not Qualify question.). Type exactly as follows:


IF [People in household NU] = 1

GOTO “0-Do Not Qualify and Exit”



  1. Double click on another new page. Move it to Step 2. Rename it 2-Pregnant (Condition BEFORE). We’ll come back to this one soon.

  2. Double click on another new page. Move it to Step 2. Rename it 3-Children (Set Variable). We’ll come back to this one soon.

  3. Go back to 2-Pregnant (Condition BEFORE) and reopen it.

    1. Notes: Question is only asked if the user is female.

    2. Question text: Are you currently pregnant?

    3. No fields.

    4. Create 2 buttons.

      1. Button 1: Label: Yes; Variable Name: Pregnant TF; Default value: True

      2. Button 2: Label: No; Variable Name: Pregnant TF; Default value: False

    5. BEFORE logic:


IF [User Gender] = “Male”

GOTO “3-Children (Set Variable)”



  1. Open 3-Children (Set Variable).

    1. Question text (for purposes of this Sample Exercise, we’re assuming the user has children. In a real interview, you should have a question before that asks IF the user has children and only displaying this question if they answer yes.): How many children do you have?

    2. Create 1 field. Type: Number (Pick from list); no label; Variable: Number child NU; check “Required” box; Min value: 1; Max value: 10

    3. Scroll down to the AFTER Logic section. This is where we will create a condition to set a new variable [Child or children TE] to the correct word based on how many children the user says they have. You can then use [Child or children TE] later in the interview in a macro to call out the correct word.


IF [Number child NY] >1

SET [Child or children TE] TO “children”


SET [Child or children TE] TO “child”


  1. Double click on the final new page. Move it to Step 3. Rename it 1-Success.

    1. Question text: Congratulations you’ve finished your Sample Exercise on Scripting Logic Statements!

  2. To complete this Sample A2J Guided Interview, we need to connect all the questions now. To connect questions, you set the Destination on each question to the next one in the line. Double click on each question in the following list and make sure it’s connected to the next question listed as follows:

    1. 1-Welcome to 1-Name

    2. 1-Name to 2-DOB (Condition AFTER)

    3. 2-DOB (Condition AFTER) to 1-Income (Multiple Conditions)

    4. 1-Income (Multiple Conditions) to 2-Pregnant (Condition BEFORE)

    5. 2-Pregnant (Condition BEFORE) to 3-Children (Set Variable)

    6. 3-Children (Set Variable) to 1-Success

  3. Now it’s time to test your interview to ensure it flows as it is supposed to. Either click the Preview Tab or open 1-Welcome and then click the Preview button within that question. It’s best to preview your interview with the Variables/Script window open. To open it, when in Preview mode, click the “Variables/Script” button in the bottom left hand corner of the interview. This will open a panel where you can see the values that are being assigned to different variables, the path the interview is following, and the logic statements being evaluated real time. You can re-enter editing mode by clicking “Edit this” to edit the question you are currently viewing or “Resume Edit” to edit the question you entered Preview mode from.


Congratulations on successfully completing this Sample Exercise. If you have any questions or comments, feel free to reach out to our A2J Author Project Manager Jessica Frank at