Automatically Assign Answers to a Variable

Variables normally get their values from the answers users enter during an interview, but sometimes you may want to assign an answer to a variable instead of allowing the user to specify the answer.

For example, a document might include the address of the client and, in another place, the address of the client’s spouse. Once the client’s address has been entered by the user, you could use a SET instruction to automatically fill in the same address for the spouse, since it will be the same.

SET instructions are inserted using a Computation variable, which you can insert in the template where you want the SET instruction to take effect.

When you set a variable to a value, you should clear the Save in answer file option for the variable (Advanced tab of the variable editor). That way, when HotDocs builds the interview, the answer can be set without prompting the user to save the answer file. (A changed answer file warning like this could be puzzling to users, especially if users don't add or change any answers in the interview.)

To set a variable to a value

  1. Create a Computation variable. (See Customize a Computation Variable.)
  2. From the Instruction models list, drag the SET VAR TO VALUE instruction into the Script field.
  3. Drag a variable you want to receive the new answer from the Variables list onto the VAR placeholder.
  4. Replace the VALUE placeholder with the answer you are assigning to the variable. You can do this by dragging a variable name from the Variables list, by dragging another instruction or expression into the Script field, or by entering an actual value. (See Values in SET Instructions for more details about these different types of values.)
  5. Click OK after the placeholders have been replaced with actual values.

You should never SET a variable's value and then cause the variable to be asked later in the template. If you do this, the value assigned by the SET instruction will always overwrite users' answers. If you want to suggest an answer for users but allow them to change it, use the DEFAULT instruction. (See DEFAULT VAR TO VALUE instruction model and Differences Between SET and DEFAULT Instructions.)

To set two or more options for a Multiple Choice variable, separate each option with a vertical bar (for example, SET MC Variable TO "Option1|Option2|Option3").

If you intend to SET values for all the variables in a repeated dialog, you should make sure the Trim endmost iterations whose answers are grayed or hidden option is turned off for that dialog. Otherwise the dialog’s COUNT and/or the number of repetitions that show up in the interview outline may be unpredictable.