Expression: Difference between revisions

From ContactsLaw Documentation
No edit summary
No edit summary
Line 64: Line 64:


=== Mathematical ===
=== Mathematical ===
These operators work with whole and decimal numbers only.
These operators work with whole and decimal numbers only. The result is also a number.
{| class="wikitable"
{| class="wikitable"
|+
|+
Line 88: Line 88:


=== Comparison ===
=== Comparison ===
These operators work with numbers and date/time values.
These operators work with numbers and date/time values. The result is either ''yes'' or ''no''.
{| class="wikitable"
{| class="wikitable"
|+
|+
Line 119: Line 119:
|Is greater than or equal to
|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. The result of comparing an empty value with a non-empty value is always ''No''.
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. The result of comparing an empty value with a non-empty value is always ''no''.


=== Conditional ===
=== Conditional ===
These operators work with yes/no values.
These operators work with yes/no values. The result is also either ''yes'' or ''no''.
{| class="wikitable"
{| class="wikitable"
|+
|+
Line 143: Line 143:


=== Text ===
=== Text ===
These operators work with text.
These operators work with text. The result is also text.
{| class="wikitable"
{| class="wikitable"
|+
|+

Revision as of 12:07, 19 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 represents multiple contacts/matters/etc then the expression produces multiple results. Unless you specify otherwise, multiple results 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 arguments (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 information in this section relates to a pre-release version of ContactsLaw and is not representative of the final product.

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).

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.

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. 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.