Retrieving a Specific Answer from a List
At times, you may need to merge a single answer from a repeated list of answers. For example, you might have a list of board members, but later in the document you need to merge the name of just the alternate in the list. You can do this by using explicit indexing. Type the index number of the answer you need between brackets, immediately after the variable name, to merge only that list item.
To use explicit indexing
- Ensure you have a variable that contains repeated values you can reference.
- Insert a variable placeholder for the value you wish to merge, e.g. Alternate.
- Add the variable to a dialog.
- In the Script tab of the dialog, use the SET instruction. For example:
SET Alternate TO BoardMember[2]
In this example Alternate is the variable you place in the template and BoardMember references the list that contains the value you wish to merge. The number in square brackets immediately after BoardMember refers to the index of the repetition you need, in this case the second answer in the list.
- Click Save.
HotDocs uses 1-based indexing. The first item in a list is [1].
Important Considerations
Variable types
The variable types must match. If BoardMember is a Text variable, Alternate must also be a Text variable.
Missing indices
If you reference an index that does not exist (for example BoardMember[3] when only two answers exist), HotDocs treats the value as unanswered.
Limits
The Maximum WHILE iterations limit controls the maximum-allowed explicit index. (You set this value at the Component File Properties dialog box.)
When to avoid REPEAT
Normally, you must position a repeated variable inside a REPEAT instruction. However, when you specify a particular list entry using explicit indexing, do not include a REPEAT instruction, rather, place the explicitly indexed variable directly in the template or use it in SET as shown above.
Explicit indices are evaluated at runtime against interview answers, not against the order of variables in the template.
To merge a particular answer from a nested repeat
To merge a specific answer from a nested repeat, include the numbers of each level in the path, beginning with the first repeat level. During the interview, HotDocs retrieves the information from the correct levels of the nested repeat based on the numbers provided.
For example, if you need to merge the birthday of the second beneficiary's fourth child's third grandchild, you would specify:
SET Date TO GrandchildDOB[2,4,3]
Inside the brackets ( [ ] ), type the first number of the path, followed by a comma, then the second number, followed by a comma, and so on. Do not put spaces after the commas, and do not put a comma after the last number.
As you specify records from a nested repeat, enter all necessary numbers in the path. HotDocs always uses a 1 if a necessary number is missing, and it always places the 1 after the number(s) you entered. If you don’t enter any numbers, HotDocs uses [1,1,...] as the default number path.
To set an explicit index in a form field
- Create the variable.
- Select the field and open the Field Properties dialog box.
- In the Variable field, enter the explicit index immediately after the variable name, using square brackets (for example, GrandchildDOB [2,4,3]).