Function

From ContactsLaw Documentation
Revision as of 13:07, 19 August 2025 by Bradley Smith (talk | contribs)

A function is a type of expression that computes a result based on its arguments (inputs). Function calls can be nested within each other.

This page documents each of the functions that can be used in ContactsLaw. The documentation is also available within the Desktop App.

Text Functions

These functions operate on text.

An(word)

Produces 'a' or 'an' according to grammar rules for a particular word.

  • word - Word.
Filter(text, [allowed, ...])

Filters text to allow only specific values.

  • text - Text.
  • allowed - Allowed values.
Find(text, find)

Tests whether text contains a particular word/phrase (yes/no).

IsAre(value)

When there are two or more values, produces 'are'. Otherwise, produces 'is'.

  • value - Number or set of values.
Link(url, [text = Empty])

Produces Markdown for an external link.

  • url - URL.
  • text - Link text.
Lower(text)

Converts text to 'lowercase'.

  • text - Text.
NoBreak(text)

Prevents text from wrapping at word boundaries by replacing whitespace characters with non-breaking spaces.

  • text - Text.
Optional([values, ...])

Joins consecutive values together. If any value is empty, the result is also empty.

  • values - Any value.
Plural(word)

Converts a word to its plural.

  • word - Singular form of the word.
PluralOf(value, word)

Converts a word to its plural when there are two or more values.

  • value - Number or set of values.
  • word - Singular form of the word.
Possessive(word)

Adds a possessive apostrophe to a word according to grammar rules.

  • word - Word.
Replace(text, find, replace)

Replaces all occurrences of a particular word/phrase in the text.

  • text - Subject text.
  • find - Word/phrase to find. Can be a regular expression.
  • replace - Replacement text. Can include capture groups.
ReplaceWith(text, find, replace)

Replaces the entire value if it contains a particular word/phrase.

  • text - Subject text.
  • find - Word/phrase to find. Can be a regular expression.
  • replace - Replacement text. Can include capture groups.
Sentence(text)

Converts text to 'Sentence case'.

  • text - Text.
Title(text)

Converts text to 'Title Case'.

  • text - Text.
Upper(text)

Converts text to 'UPPERCASE'.

  • text - Text.

Number Functions

These functions operate on numbers.

Avg(set)
Avg()

Calculates the average of a set.

  • set - A set of values.

Note: Avg() is short-hand for Avg(current)

Currency(number, [decimals = 2], [thousands = Yes])

Formats a currency value as text.

  • number - Number.
  • decimals - Decimal places.
  • thousands - Use thousands separator (Yes/No).
CurrencyInWords(number)

Converts currency to an amount in words.

  • number - Number.
Decimal(number, [decimals = 2], [thousands = Yes])

Formats a decimal number as text.

  • number - Number.
  • decimals - Decimal places.
  • thousands - Use thousands separator (Yes/No).
IsBetween(value, min, max)

Tests whether a number or date/time value falls within a given range (yes/no).

  • value - Number or date/time.
  • min - Minimum number or date/time (inclusive).
  • max - Maximum number or date/time (inclusive).
IsEven(number)

Tests whether a number is even (yes/no).

  • number - Number.
IsOdd(number)

Tests whether a number is odd (yes/no).

  • number - Number.
Max(set)
Max()

Calculates the largest value in a set.

  • set - A set of values.

Note: Max() is short-hand for Max(current)

Min(set)
Min()

Calculates the smallest value in a set.

  • set - A set of values.

Note: Min() is short-hand for Min(current)

Number(number, [thousands = Yes])

Formats a whole number as text.

  • number - Number.
  • thousands - Use thousands separator (Yes/No).
NumberInWords(number)

Converts a number to words.

  • number - Number.
Ordinal(number)

Adds the ordinal suffix (st/nd/rd/th) to a number.

  • number - Number.
Random(min, max)

Generates a random number in a given range.

  • min - Smallest number (inclusive).
  • max - Largest number (inclusive).
Sum(set)
Sum()

Calculates the sum of the values in a set.

  • set - A set of values.

Note: Sum() is short-hand for Sum(current)

WordsToCurrency(text)

Converts an amount in words to currency.

  • text - Text.
WordsToNumber(text)

Converts words to a number.

  • text - Text.

Conditional Functions

These functions are used to make decisions.

AllEmpty(set)
AllEmpty()

Tests whether all of the values in a set are empty (yes/no).

  • set - A set of values.

Note: AllEmpty() is short-hand for AllEmpty(current)

AllNotEmpty(set)
AllNotEmpty()

Tests whether all of the values in a set are not empty (yes/no).

  • set - A set of values.

Note: AllNotEmpty() is short-hand for AllNotEmpty(current)

Case(value, [cases, ...])

Matches a value against a set of cases. See also: When and Else

  • value - Value to test.
  • cases - Cases to match.
Contains(set, value)
Contains(value)

Tests whether a set contains a particular item (yes/no).

  • set - A set of values.
  • value - Any value.

Note: Contains(value) is short-hand for Contains(current, value)

DefaultIfEmpty(value, [default, ...])

Provides a default for when a value is empty. Short-hand for: If(IsEmpty(value), default, value)

  • value - Any value.
  • default - Value if empty.
DefaultIfMultiple(value, default)

Provides a default for when there are two or more values. Short-hand for: If(Count(value) > 1, default, value)

  • value - Any value.
  • default - Value if multiple.
Else(result)

Specifies a result for when nothing matches the value in a Case function.

  • result - Value if no match.
If(condition, yes, [no])

Tests a condition and gives a different value depending on the result.

  • condition - Yes/no.
  • yes - Value if true.
  • no - Value if false.
Intersects(set1, set2)

Tests whether two sets have any items in common (yes/no).

  • set1 - A set of values.
  • set2 - A set of values.
IsEmpty(value)

Tests whether a set or value is empty (yes/no).

  • value - Any value.
IsNotEmpty(value)

Tests whether a set or value is not empty (yes/no).

  • value - Any value.
When(value, result)

Specifies a result for a particular value in a Case function.

  • value - Value to match.
  • result - Result if matched.

Date and Time Functions

These functions operate on date and time values.

AddDays(date, days)

Adds a number of days to a date/time value.

  • date - Date/time.
  • days - Number of days. Use negative numbers to subtract.
AddHours(date, hours)

Adds a number of hours to a date/time value.

  • date - Date/time.
  • hours - Number of hours. Use negative numbers to subtract.
AddMinutes(date, minutes)

Adds a number of minutes to a date/time value.

  • date - Date/time.
  • minutes - Number of minutes. Use negative numbers to subtract.
AddMonths(date, months)

Adds a number of months to a date/time value.

  • date - Date/time.
  • months - Number of months. Use negative numbers to subtract.
AddWeekDays(date, days)

Adds a number of weekdays (skipping over weekends) to a date/time value.

  • date - Date/time.
  • days - Number of weekdays. Use negative numbers to subtract.
AddYears(date, years)

Adds a number of years to a date/time value.

  • date - Date/time.
  • years - Number of years. Use negative numbers to subtract.
Age(date)

Gets the number of years that have elapsed since a particular date, rounded down.

  • date - Date/time.
Date(date, format)

Formats a date as text.

  • date - Date/time.
  • format - Date/time format. Can be pre-defined (e.g. DateStyle1) or a custom format.
Day(date)

Gets the day component of a date/time value.

  • date - Date/time.
Days(date1, date2)

Gets the number of days between two date/time values.

  • date1 - Date/time.
  • date2 - Date/time.
Hour(date)

Gets the hour component (0-23) of a date/time value.

  • date - Date/time.
HoursAndMinutes(minutes)

Expresses a quantity of minutes in hours and minutes.

  • minutes - Number of minutes.
IsSameDate(date1, date2)

Tests whether two values represent the same date (ignoring time).

  • date1 - Date/time.
  • date2 - Date/time.
IsSameTime(time1, time2)

Tests whether two values represent the same time (ignoring date).

  • date1 - Date/time.
  • date2 - Date/time.
MakeDate(year, [month], [day])

Constructs a date value from its year, month and day components.

  • year - Year number.
  • month - Month number (1-12).
  • day - Day number (1-31).
Minute(date)

Gets the minute component (0-59) of a date/time value.

  • date - Date/time.
Minutes(date1, date2)

Gets the number of minutes between two date/time values.

  • date1 - Date/time.
  • date2 - Date/time.
Month(date)

Gets the month component of a date/time value.

  • date - Date/time.
Now()

Today's date, including the current time.

SetTime(date, [hour], [minute])

Sets the time component of a date/time value.

  • date - Date/time.
  • hour - Hour (0-23).
  • minute - Minute (0-59).
SetTimeZone(date, tz)

Changes the time zone of a date/time value.

  • date - Date/time.
  • tz - Offset (-14 to 14).
Today()

Today's date.

Year(date)

Gets the year component of a date/time value.

  • date - Date/time.
Years(date1, date2)

Gets the number of years between two date/time values, rounded down.

  • date1 - Date/time.
  • date2 - Date/time.

Set Functions

These functions operate on sets of values.

Count(set)
Count()

Counts the number of items (including empty values) in a set.

  • set - A set of values or assets.

Note: Count() is short-hand for Count(current)

CountNotEmpty(set)
CountNotEmpty()

Counts the number of non-empty values in a set.

  • set - A set of values or assets.

Note: CountNotEmpty() is short-hand for CountNotEmpty(current)

Each(set, expression)

Evaluates an expression for each item in a set.

  • set - A set of values or assets.
  • expression - Any expression.
Except(set, excluded)
Except(excluded)

Gets the items in a set which do not appear in some other set.

  • set - A set of values or assets.
  • excluded - Values/assets to exclude.

Note: Except(excluded) is short-hand for Except(current, excluded)

First(set)
First()

Takes the first item in a set.

  • set - A set of values or assets.

Note: First() is short-hand for First(current)

Intersection(set1, set2)

Gets the intersection of two sets.

  • set1 - A set of values or assets.
  • set2 - A set of values or assets.
Item(set, position)
Item(position)

Takes the n-th item in a set.

  • set - A set of values or assets.
  • position - Position of the desired item.

Note: Item(position) is short-hand for Item(current, position)

Join(set, [separator = ", "])
Join([separator = ", "])

Joins a set of values together with a separator between each item.

  • set - A set of values.
  • separator - Separator between each item.

Note: Join([separator]) is short-hand for Join(current, [separator])

Last(set)
Last()

Takes the last item in a set.

  • set - A set of values or assets.

Note: Last() is short-hand for Last(current)

Lines(set)
Lines()

Joins a set of values together with each item on a separate line.

  • set - A set of values.

Note: Lines() is short-hand for Lines(current)

List(set, [conjunction = "and"])
List([conjunction = "and"])

Joins a set of values together using commas and a conjunction between the last two items.

  • set - A set of values.
  • conjunction - The word that is inserted between the last two items.

Note: List([conjunction]) is short-hand for List(current, [conjunction])

NonEmpty(set)
NonEmpty()

Filters a set by excluding empty values.

  • set - A set of values or assets.

Note: NonEmpty() is short-hand for NonEmpty(current)

Paragraphs(set)
Paragraphs()

Joins a set of values together with each item in a separate paragraph.

  • set - A set of values.

Note: Paragraphs() is short-hand for Paragraphs(current)

RSort(set, [smart = Yes])
RSort([smart = Yes])

Sorts the items in a set in reverse order.

  • set - A set of values or assets.
  • smart - Whether to use natural language sorting rules.

Note: RSort([smart]) is short-hand for RSort(current, [smart])

Set([values, ...])

Creates a set from one or more values.

  • values - Values.
Slice(set, [start = 1], [count])
Slice([start = 1], [count])

Creates a subset of a set.

  • set - A set of values or assets.
  • position - Starting position.
  • count - Number of items (maximum) to include.

Note: Slice([start], [count]) is short-hand for Slice(current, [start], [count])

Sort(set, [smart = Yes])
Sort([smart = Yes])

Sorts the items in a set.

  • set - A set of values or assets.
  • smart - Whether to use natural language sorting rules.

Note: Sort([smart]) is short-hand for Sort(current, [smart])

Union(set1, set2)

Gets the union of two sets.

  • set1 - A set of values or assets.
  • set2 - A set of values or assets.
Unique(set)
Unique()

Filters a set by excluding duplicate values.

  • set - A set of values or assets.

Note: Unique() is short-hand for Unique(current)

Where(set, expression)

Creates a subset of a set containing only the items that satisfy a yes/no expression.

  • set - A set of values or assets.
  • expression - Yes/no expression.

Contact Functions

These functions operate on contact assets.

ObjectivePronoun(contact)

Gets the objective pronoun (him/her/them) for one or more contacts.

  • contact - Contact.
PossessivePronoun(contact)

Gets the subjective pronoun (his/her/their) for one or more contacts.

  • contact - Contact.
SubjectivePronoun(contact)

Gets the subjective pronoun (he/she/they) for one or more contacts.

  • contact - Contact.

Telephone Functions

These functions operate on telephone/fax numbers.

Telephone(phone, [format])

Formats a telephone number.

  • phone - Telephone number.
  • format - Format (Extension, Local, Domestic or International).

Tag Functions

These functions operate on tags.

HasTag(item, tag)

Determines whether an item has a particular tag (yes/no).

  • item - A taggable item (e.g. contact).
  • tag - Name of the tag.

Special Purpose Functions

These functions are used for special purposes.

Asset(name, expression)

Evaluates an expression using an asset whose name is not known ahead of time.

  • name - Name of the asset.
  • expression - Any expression.
Field(item, field)

Gets the value of a custom field (except tables) on an asset.

  • item - Item containing the field (e.g. matter).
  • field - Name of the field.
Resource(type, id)

Creates a reference to a subscriber-specific resource in ContactsLaw.

  • type - Resource type.
  • id - Resource identifier.

Table Functions

These functions operate on tables (or sets of rows).

Column(table, column)
Column(column)

Gets the value(s) in a particular column of a table.

  • table - Table (or set of rows).
  • column - Name of the column.

Note: Column(column) is short-hand for Column(current, column)

Query(item, field, select, [where = Empty], [aggregate = Empty])

Performs a query on a table loaded from a custom field on an asset.

  • item - Item containing the table (e.g. matter).
  • field - Name of the field (Table Row).
  • select - Expression that is evaluated on each row.
  • where - Yes/no expression that determines which rows to include.
  • aggregate - Expression that combines the results.
RSortBy(table, column, [smart = Yes])
RSortBy(column, [smart = Yes])

Sorts the rows in a table by a particular column in reverse order.

  • table - Table (or set of rows).
  • column - Name of the column.
  • smart - Whether to use natural language sorting rules.

Note: RSortBy(column, [smart]) is short-hand for RSortBy(current, column, [smart])

SortBy(table, column, [smart = Yes])
SortBy(column, [smart = Yes])

Sorts the rows in a table by a particular column.

  • table - Table (or set of rows).
  • column - Name of the column.
  • smart - Whether to use natural language sorting rules.

Note: SortBy(column, [smart]) is short-hand for SortBy(current, column, [smart])

Table(item, field, [headings = Yes], [columns, ...])

Loads a table from a custom field on an asset.

  • item - Item containing the table (e.g. matter).
  • field - Name of the field (Table Row).
  • headings - Include column headings (yes/no).
  • columns - Names of the columns to include.