Customize a Computation Variable

You can use a Computation variable to calculate number, date, true/false, and text values based on answers a user enters. The computed value can then be merged into the assembled document. Computation variables can also be used to group several instructions or expressions for insertion into a template, which results in quicker assembly.

Creating a computation requires you to write a script using the HotDocs scripting language. The actual process of writing a script depends on your skill level in using this language. If you're a beginner, you can drag scripting models into the Script field inside the script editor and allow HotDocs to guide you in filling in the required information. With experience, you can type the script directly in the field.  Some developers may wish to create Local Variables and Parameters that are specific to the computation.

The title bar of the Computation Editor contains information that can help you evaluate the correctness of the script as you write it. When a script is invalid (meaning it does not adhere to the rules of the HotDocs scripting language), HotDocs includes the word [Invalid] in the title bar. Once a script is valid, HotDocs then notes what type of result the script produces (for example, [Text] or [Number]).

Once a variable is created, you can edit the variable at any time.

To edit the properties of a Computation variable

  1. Insert a variable, selecting Computation as the variable type.
  2. At the Variable Field dialog box, click the Edit Component button to open the Computation Editor.
  3. In the Script field, enter a computation script.
  4. Make any changes, as described in the following table:
To Do This
Indent matching pairs of IF and REPEAT instructions Click the Auto Format button. HotDocs indents the instructions based on the level of their insertion.
Specify a default format that will be applied to all instances of the variable (except when a field-specific format has been assigned) Select a format from the Default format drop-down list.

Optionally, to keep the answer from breaking across lines in the document, select Non-breaking.

Save changes to the variable without closing the variable editor Click Save.

You can create new variables directly at the Computation Editor. Make sure the Components list contains the type of variable you want to create, and then click the New Component button. Similarly, you can edit an existing variable in the list by double-clicking it.

If you experience errors when writing a script, it may be because you are using the instruction and expression keywords incorrectly.  If you aren't receiving errors, but the script produces results you don't expect, you can examine the script line by line to see where the logic is flawed.

HotDocs will not let you close the Computation Editor or save a script if the script is invalid. If you need to close or save, you must either comment out the script (by highlighting the script and clicking the Comment Block button) or place a QUIT instruction at the beginning of the script (see QUIT).