Expressions Overview

An expression is a single statement in the HotDocs scripting language that resolves to a value; an expression can range in complexity from a single literal value or a variable (which represents a value stored in an answer set) to a calculation based on any combination of literal values, variables, operators, or functions (whether system functions or computation components). For example, the expression YEARS FROM(DateVar1, TODAY) tells HotDocs to calculate the number of years between today's date and a value your template user supplies for DateVar1 in the interview.

In this topic Hide

  1. Overview
  2. Common Tasks
  3. Workflow
  4. Possible Elements of an Expression
  5. Single Line Expressions
  6. Expression Examples
  7. Common Reference Topics

Overview

An expression tells HotDocs to evaluate its elements and resolve all of them to a single value. The possible elements of an expression include one or more values that help HotDocs to calculate a final value from the expression. References to such values can include a literal, a reference to a variable, or a call to a function, among others. For example, when a placeholder field references a variable, the variable reference acts as a simple expression that HotDocs evaluates to locate and access the answer to the relevant interview question, and then pass in the answer as the value that replaces the placeholder field during document assembly.

Common Tasks

Among others, expressions enable you to perform the following common tasks:

Workflow

To help you create expressions, Author provides system function and operator models. When you write a script on the Script tab of a computation or dialog, you can drag and drop a model onto the Script tab from the Model tab to its right.  Once on the Script tab, the model shows you the syntax HotDocs expects to make the function or operator work properly. You can then drag a component from the Component tab onto the red placeholders of the model.

Alternatively, you can select the placeholders, then type the proper value. When typing, HotDocs provides an auto-complete feature that tries to help you by guessing what you are typing. If you push CTRL + SPACE BAR on your keyboard, a list of syntax features appears from which you can select the element you need. You use the down and up arrow keys to change the selected element in the list.

HotDocs also provides syntax highlighting and error validation to help you create your expressions. If your syntax is correct, elements appear in various colors and font weights to help you better read your script. If your syntax is incorrect, HotDocs underlines the offending element with a red squiggly line to alert you that there is an error in the syntax. If you do not have any errors in your syntax, you can test your expression by clicking the Test button at the top of the current component editor.

Possible Elements of an Expression

When you are creating an expression using the syntax of the HotDocs scripting language, the elements you can add to an expression include:

You can also use local variables in an expression.

Single Line Expressions

There are times when you want to create an expression directly within your template. To facilitate this, HotDocs enables you to add a placeholder field for an other expression. When you add such a field, you can type a single line expression into that field.

This single line expression does not provide the syntax highlighting and error validation available in the computations you write in the Component Studio.

Expression Examples

To better understand expressions, review the following examples. Remember, each expression implicitly tells HotDocs to calculate a single value by evaluating all the elements (whether these be one or many) in the expression. For more examples of expressions, see the example code provided for each function and operator.

Number Value Expressions

The following example expressions are classified as number value expressions because the expressions all resolve to a number value:

Text Value Expressions

The following example expressions are classified as text value expressions because the expressions all resolve to a text value:

Date Value Expressions

The following example expressions are classified as date value expressions because the expressions all resolve to a date value:

True/False Value Expressions

The following example expressions are classified as true/false value expressions because the expressions all resolve to a true/false value:

Common Reference Topics

Among others, the following reference topics may relate to this conceptual area: