Expression: Difference between revisions
Line 100: | Line 100: | ||
|Modulus (remainder) | |Modulus (remainder) | ||
|} | |} | ||
Numbers formatted as text are treated as numbers. | Numbers formatted as text are treated as numbers. Empty values are treated as zero, except when adding two empty values (the result of which is also empty). | ||
=== Comparison === | === Comparison === |
Latest revision as of 13:12, 20 August 2025
An expression refers to either:
- A literal value, such as a number (e.g.
123
) or a piece of text (e.g."Hello world"
); or - A group of words or symbols that describes how to obtain a value (e.g.
Contact.ShortName
,Today()
).
ContactsLaw allows the use of expressions in document templates, automatic descriptions for document types and workgroups, as well as various other areas. This is the basis for generating content that draws upon data from contacts, matters and so on.
Types of Expressions
Type | Example Expressions | Example Results | Remarks |
---|---|---|---|
Literal | 123 "Hello world"
|
123 "Hello world"
|
To include double-quote characters inside a string literal, prefix with a backslash (i.e. \" ).
|
Asset | Contact Matter Address
|
Assets do not produce any result directly, but can be used in conjunction with some functions, e.g. Count(Contact) might evaluate to 3 if the asset represented three parties on a matter.
| |
Property | Contact.ShortName Contact.Gender Matter.Code Address.Country
|
"John Smith" "Male" "678-1" "Australia"
|
Properties belong to assets. If an asset resolves to multiple contacts/matters/etc then the expression produces a set. Unless you specify otherwise, sets appear as a list of values, separated by commas (e.g. "John Smith, Fred Baker, Jane Doe" ).
|
Operator | + , - , * , /
|
Arithmetic operators compute numbers. Conditional operators produce either Yes or No .
| |
Function | IsNotEmpty(Contact.LastName) Plural("word") If(Count(Contact) < 3, "friends", "acquaintances")
|
Yes "words" "acquaintances"
|
Functions compute a result based on their parameters (inputs). Function calls can be nested within each other. |
Constant | NewLine NewParagraph
|
"␊" "␍"
|
Constant expressions provide a short-hand way of inserting frequently-used values, as well as text that cannot normally be entered directly (e.g. tab spaces). |
Repetition | current.ShortName current.Country index
|
"John Smith" "Australia" 3
|
These expressions can only be used inside a repetition block, where they correspond to either the current instance of the repeated asset or a number indicating how many times the block has been repeated so far. |
Desktop App
The Desktop App includes various features to assist in writing and utilising expressions:
- Rich text editing - In situations where content may consist of formatted text and expressions, you can edit expressions directly. Text formatted as an expression appears in a monospaced font with a grey background.
- Syntax highlighting - To improve readability, the various components of expressions are colour-coded. Syntax errors are underlined (in the same manner as spelling errors in normal text).
- Automatic completion - Suggestions for assets, functions and other components of expressions appear as you type. You can double-click or press the Tab key to accept a suggestion.
- Inline documentation - Hover the mouse over components of an expression to show the relevant documentation.
- Previews - In many cases, you can toggle between editing an expression and previewing the result (using example data).
Empty Expressions
Several operators and functions exhibit different behaviour depending on whether an expression is "empty".
The following are all considered empty:
- The
Empty
constant - An empty string literal; i.e.
""
- A property of an asset that has not been specified
- A set that does not contain any values
- A set that contains only empty values
Empty expressions may produce different results depending on how they are used. For example: counting the number of values in a set that does not contain any values will yield zero, while counting the number of values in a set consisting of the Empty
constant will yield 1
.
Various functions are provided to ignore or filter out empty values in situations where they are not desired.
Operator Reference
This section documents each of the operators that can be used in expressions.
Mathematical
These operators work with whole and decimal numbers only. The result is also a number.
Operator | Purpose |
---|---|
+
|
Add |
-
|
Subtract |
*
|
Multiply |
/
|
Divide |
%
|
Modulus (remainder) |
Numbers formatted as text are treated as numbers. Empty values are treated as zero, except when adding two empty values (the result of which is also empty).
Comparison
These operators work with numbers and date/time values. The result is either yes or no.
Operator | Synonym(s) | Purpose |
---|---|---|
=
|
eq
|
Is equal to |
<>
|
!= , neq
|
Is not equal to |
<
|
lt
|
Is less than |
<=
|
lte
|
Is less than or equal to |
>
|
gt
|
Is greater than |
>=
|
gte
|
Is greater than or equal to |
Numbers formatted as text are treated as numbers. Date/time values formatted as text are treated as dates including time; if not specified, the time is assumed to be midnight. For all other date/time values, the comparison takes time into account only if the value on the left-hand side of the operator includes time. The result of comparing an empty value with a non-empty value is always no.
Conditional
These operators work with yes/no values. The result is also either yes or no.
Operator | Purpose |
---|---|
and
|
And (yes if both are yes) |
or
|
Or (yes if either are yes) |
not
|
Not (no if yes, yes if no) |
Other types of values are converted to yes or no according to the following rules:
- Text - No if empty, "no", "false" or "0"; otherwise yes.
- Number - No if zero; otherwise yes.
Text
These operators work with text. The result is also text.
Operator | Synonyms | Purpose |
---|---|---|
&
|
+
|
Concatenate (join) |
Note: The +
operator can be used for both addition and concatenation; if at least one value is a number then addition is performed. Use the &
operator to avoid ambiguity.