Sample Exercise: Repeat Loops
This exercise was designed to teach you the basics of repeat loops in A2J Author, creating both an A2J Guided Interview and an A2J Text Template.
There are two components to a completely automated document - the A2J Guided Interview which interacts with the end user and asks them questions, and the A2J Text Template, which creates the actual document for the end user.
A2J Guided Interview
We are first going to create an A2J Guided Interview that will be paired with your A2J Template. For the purposes of this Sample Exercise, the interview will be fairly short.
-
Log into your www.a2jauthor.org account. If you aren’t sure how to create an account, check out this resource.
-
Once logged in, go to the “Author” tab and click it.
-
Then click “Run A2J Author”.
-
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. To learn more about authoring in A2J Author 6.0, check out our Authoring Guide.
-
Go to the About tab and change the title of your interview to Sample Exercise: Repeat Loops. You can select any guide avatar options to customize the Guide avatar. You should also click over to the Author tab inside the About tab in order to add your information as the author of this interview.
-
A new A2J Guided Interview comes pre-populated with 4 questions. We’re going to have a total of 9 questions in this interview. Click the New Page button at the top of the screen 5 times. Your screen should something look like this:
-
Now we’re going to create the Steps that will organize our questions. Go to the Steps Tab. By default, there are 4 steps in each A2J Guided Interview. That is all that we will need for this Sample Exercise. Rename the steps as follows:
-
Step 0 : Introduction
-
Step 1: Ask for Number First
-
Step 2: Ask to Add More
-
Step 3: The End
-
It should look like this:
-
Go to the Variables tab and create the following variables.
-
Asset value TE; type: number; repeating: yes (Check the box next to “Check if multiple values”)
-
AssetCount; type: number; repeating: no
-
Asset name TE; type: text; repeating: yes
-
Child birth date DA; type: date; repeating: yes
-
Child name first TE; type: text; repeating: yes
-
ChildCount; type: number; repeating: no
-
Have assets TF; type: true false; repeating: no
-
Have children TF; type: true false; repeating: no
-
Number of children NU; type: number; repeating: no
-
-
Go back to the Pages tab. Double click on 1-Introduction.
-
Rename it 1-Name and Gender
-
Question text: Welcome to the sample A2J Guided Interview for Repeat Loops. Please enter your name and gender.
-
Create two fields.
-
Field 1-Type: Text; Label: Name; Variable: Client first name TE
-
Field 2 - Type: Gender; Label: Gender; Variable:User Gender
-
-
Don’t worry about the button for now. The Continue label is sufficient and we will update the destinations at the end of this section.
-
-
Double click on 2-Name. Change the question name to 2-Have children?
-
Question text: Do you have any children?
-
Delete the 3 fields in the question. You won’t need them.
-
Scroll down to the Buttons section and create 1 additional button (by default all questions come with 1 button).
-
Button 1- Label: Yes; Variable: Have children TF; Default value: true
-
Button 2 - Label: No; Variable: Have children TF; Default value: false
-
-
-
Double click on 3-Gender. Change the question step to Step 1; change the page name to 1-How Many Children?
-
Question text: How many children do you have?
-
Go to the 1 existing field and make the following changes:
-
Field type: Number (Pick from list)
-
Label: none
-
Variable: Number of children NU
-
Required: yes
-
Min Value: 1
-
Max Value: 9 (the min and max create the list of options that the end user can pick from)
-
-
Go to the Buttons section (this is where we will initialize the counting variable to be used in the repeat loop about the user’s children)
-
Label: Continue
-
Repeat options: Set Counting Variable to 1
-
Counting Variable: ChildCount
-
-
-
Double click on 1-Question 1in Step 1. Change the name to 2-Child’s name.
-
Question text: What is the name of the %%ordinal([ChildCount])%% child?
-
This will display the ordinal version of the counting variable. Ex. What is the name of your 8th child?
-
Add the counting variable ChildCount to the counting variable field at the bottom of the question text section.
-
-
Create 1 field.
-
Field- Type: Text; Label: First name:; Variable: Child first name TE; check the “Required” box.
-
-
-
Double click on a new question page. Change the Step to Step 1. Change the question name to 3-Child’s birthdate.
-
Question text: What is %%[Child name first TE#ChildCount]%%’s date of birth?
-
This macro will call out the name the user just gave you in 2-Child’s name.
-
-
Add the counting variable ChildCount to the counting variable field at the bottom of the question text section.
-
Create 1 field.
-
Field- Type: Date MM/DD/YYYY; Label: Birth date:; Variable: Child birth date DA; Check the required box.
-
-
Go to the Buttons section
-
Label: Continue
-
Repeat Options: Increment Counting Variable
-
Counting Variable: ChildCount
-
-
Go to the Advanced Logic section, the After box. Type the following logic statement into that box (make sure to type it in, not copy and paste).
-
-
Double click on a new question page. Change the Step to Step 2. Change the name to 1-Do you have any?
-
Question text: Do you have any assets over $100?
-
Create two buttons.
-
Button 1- Label:Yes; Variable: Have assets TF; Default value: true
-
Repeat Options: Set Counting Variable to 1
-
Counting Variable: AssetCount
-
-
Button 2- Label: No; Variable: Have assets TF; Default value: false
-
-
Advanced logic-Before section: SET [ChildCount] to [Number of children NU]
-
This will lock the child count to the number of children, now that the end user has completed the repeat loop about children.
-
-
-
Double click on a new question page. Change the Step to Step 2. Change the name to 2-Assets name.
-
Question text: What is your %%ordinal([AssetCount])%% asset over $100 and the estimated value?
-
Add the counting variable AssetCount to the counting variable field at the bottom of the question text section.
-
Create two fields.
-
Field 1- Type: Text; Label: Asset name; Variable: Asset name TE
-
Field 2- Type: Number Dollar; Label: Value; Variable: Arrest no charges TF; Default value: true
-
-
-
Double click on a new question page. Change the Step to Step 2. Change the name to 3-Any more?
-
Question text: Do you have another asset over $100 to add?
-
Learn More prompt: What assets have I told you about already?
-
Help: You’ve told me about your %%[Asset name TE]%%.
-
Add the counting variable AssetCount to the counting variable field at the bottom of the question text section.
-
Create two buttons.
-
Button 1- Label: Yes; Repeat Options: Increment Counting Variable; Counting Variable: AssetCount
-
Button 2- Label: No
-
-
-
Double click on the final new question page. Change the Step to Step 3. Change the name to 1-All done
-
Question text: The end!
-
Button 1- Label: Get my document
-
Destination: [Assemble - Generate PDF document]
-
-
-
Now that we have created all of our questions, we need to connect them to one another.
-
Open up each question and go to the Buttons section. The questions should be connected through the Destination option as follows. Change any that are not connected this way.
-
1-Name and Gender to 2-Have children?
-
2-Have children? (yes button) to 1-How Many Children?
-
2-Have children? (no button) to 1-Do you have any?
-
1-How Many Children? To 2-Child’s name
-
2-Child’s name to 3-Child’s birthdate
-
3-Child’s birthdate to 1-Do you have any?
-
1-Do you have any? (yes) to 2-Asset name
-
1-Do you have any? (no) to 1-All done
-
2-Asset name to 3-Any more?
-
3-Any more? (yes) to 2-Asset name
-
3-Any more? (no) to 1-All done
-
1-All done to [Assemble - Generate PDF Document]
-
-
-
Go back to the Steps tab and ensure that your Starting Point question is set to 1-Name and Gender. When we changed 1-Introduction’s name, A2J Author may have gotten confused. If it’s not 1-Name and Gender, click the “Set Start Point” button and a list of your questions will appear. Pick 1-Name and Gender.
A2J DAT Text Template
Now we’re going to create the A2J DAT Text Template that will create the document for your end user.
-
Go to the Templates tab. Click the “Create Text Template” button in the top right hand corner. It will take you into the Text Template tool.
-
Name your template. In the “Untitled Template” field in the top panel, delete “Untitled Template” and type in “Simple Template with three elements”. Your template is automatically saved every 5 minutes, but it doesn’t hurt to hit the “Save Template” button every so often, particularly after making several changes.
-
Now we will create a rich text element. That will be assembled for everyone, regardless of their answers for the children and asset repeat loops. Click the “Rich Text” button in the “Add Elements” section to the right of the screen. This will add a text editor box to the template.
-
Click into the text editor and type: This document was created by a template within A2J Author as part of a sample exercise to learn how to create repeat loops. The two repeat loops deal with children and assets. If the user does not have children or assets over $100, this is all that will print on the form. If the user does have children, a section with their names and birthdates will appear. If the user does have assets over $100, a list of those assets will appear. The user said that their name was:
-
After the word “was:” in the last sentence we want to insert the variable for the user’s first name. To do so, click the [P] button in the editor and select the variable [Client first name TE]. A2J Author will then insert that variable’s value into the assembled document. Hit “Save & Close” in the box labeled “Text” next to the editor to close the rich text element. The following gif demonstrates the insertion of a variable.
-
-
Now we’re going to add the first IF/Else element and repeat loop. Click the “If/Else” button in the Add Elements section. In the blank field above “is true” start typing Have children TF. A2J Author should give you a list of variables that match the characters you typed to select from. Pick Have children TF. Leave “is true” in the field below it. This is the conditional statement that A2J Author will test against in order to insert the information about the children repeat loop.
-
Click into the “Add elements here” field within the If/Else element. Add a Repeat Loop. See the following gif for steps 5 and 6.
-
These are the default repeat loop options.
-
We’re going to have to make the following changes. Make your element look like this one:
-
When your element looks like the one above, hit the “Save & Close” button. We’re going to duplicate the above steps for the asset repeat loop.
-
Add an If/Else element. The condition is if Have assets TF is true.
-
Add a repeat loop element to the If/Else element.
-
Make your repeat loop element match the following:
The tricky part is to switch the repeat display from table to list. See the following gif.
-
When you’ve matched your element to the one above, hit “Save & Close”. You’ve completed your template!
-
Now that we have created both the interview and the template, we need to test our complete A2J Guided Interview. Go back to the Pages tab.
-
-
Open 1-Name and Gender. Click Preview and open the Variables/Script window
-
Go through your A2J Guided Interview and make sure that all of your variables populate and that your advanced logic works properly.
-
When you get to the end, don’t click the “Get my document” button. When you’re in Preview Mode, A2J Templates don’t assemble. Go to the Variables Box and click “Save”. This will download your answer file.
-
-
-
Go to the Template Tab and click “Test Assemble” button . It’ll prompt you to load the answer file that you saved in the step above. Once it’s loaded, click “Get PDF”.
-
Congratulations! You’ve successfully created your A2J Guided Interview and A2J DAT PDF Template. It should look like this when Test Assembled:
If you have any questions, feel free to reach out to A2J Author’s Project Manager Jessica Frank (jessica@cali.org).
You can find the completed A2J Guided Interview for this exercise here.
You can find a sample answer file here.