Computations Overview
A Computation is a type of component that enables you to create a function (using a sequence of instructions and expressions in the HotDocs scripting language) to calculate and return a value of a given value type (number, date, text, true/false); alternatively, you can create a computation that performs some other task, such as a defining an interview. For example, you can use a computation to encapsulate a large IF instruction, or to calculate monetary amounts, or find the number of years between two given dates.
Overview
A computation enables you to create a script that defines a function (a group of instructions and calculations performed or executed by software); this enables you to encapsulate these requests for answers and other similar tasks into a reusable set of instructions or expressions in a way that makes your template and its logic easier to read, understand, and maintain. For example, a computation enables you to encapsulate the sometimes-complex rules that determine when regions of your template should be included in the finished document or not, into a single computation you can call from anywhere within your template. Using a computation you can:
- Perform some action based on an answer the user provides
- Add up several dollar amounts
- Find the number of years between two given dates
- Search a user’s answer for a certain block of text
You can use the resulting values to provide answers to other questions or place the resulting value into the final document. That result can also trigger HotDocs to perform a particular task during document assembly.
Once you create a computation, you can edit the computation at any time.
Common Tasks
Among others, a computation enables you to perform the following common tasks:
- Calculating number, date, true/false, and text values
- Generating a list from a repeated dialog
- Defining a custom interview
Scripts in Computations
When you create a computation, you must also write a script using the HotDocs scripting language. How you create a script depends on your level of experience with using this language. Beginners can drag scripting models onto the script tab of the computation editor and allow HotDocs to guide you in filling in the required information. More experienced users can type the script directly into the field.
Local variables and parameters
You may want to create a local variable or parameter that is specific to a computation.
A local variable is like a regular variable, but it is only defined in the "local" context of a specific computation or dialog script. Local variables are useful in scripting situations where you would otherwise resort to defining a regular HotDocs variable just to keep track of temporary information that is not meaningful anywhere else but in this one script. These are useful for things like counters for WHILE loops and flags for IF instructions.
You should avoid giving a local variable the same name as an existing regular (non-local) variable because the computation operates on the local variable whenever that name appears in your script. To circumvent this behavior, you would need to pass in the variable name as a parameter.
A parameter is like a local variable for a particular computation. If your script requires input from a variable that will change with each interview--such as a person's age--you can create a parameter that accepts different input into the computation each time. Using a parameter enables you to create a single script that works against a number of different values inputted for a variable.
Create a list with a computation
Creating a list of answers with a REPEAT instruction inside a computation enables you to insert the list anywhere in the template.
An example of a script that uses a computation to make a list looks similar to this example:
REPEAT Decedent Information
RESULT + Decedent Name + ", " " + Date of Death + "
"
END REPEAT
Part of the example script | What it does |
REPEAT | This is a REPEAT instruction, which tells Author to display the Decedent Information dialog again. |
Create a list of answers to insert in multiple locations in a template
Creating a REPEAT instruction inside a computation generates a list of answers that you can insert in multiple locations in the same template.
Example of a script that uses a computation in this way, where Tour Information is the name of a dialog and Name of City and Venue are variable names:
""
REPEAT Tour Information
RESULT + Name of City + ", " + Venue + "
"
END REPEAT
When creating a conditional region based on a computation, computations with a result type of None cannot be selected from the drop down in the Field Editor (conditional regions based on a conditional region must evaluate to True.