Function

From ContactsLaw Documentation
Revision as of 12:22, 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)

Calculates the average of a set.

  • set - A set of values.
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)

Calculates the largest value in a set.

  • set - A set of values.
Min(set)

Calculates the smallest value in a set.

  • set - A set of values.
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)

Calculates the sum of the values in a set.

  • set - A set of values.
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.

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.
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.
AllEmpty(set)

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

  • set - A set of values.
AllNotEmpty(set)

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

  • set - A set of values.
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.
Not(condition)

Reverses the result of a condition (yes/no).

  • condition - Yes/no.
Contains(set, value)

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

  • set - A set of values.
  • value - Any value.
Intersects(set1, set2)

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

  • set1 - A set of values.
  • set2 - A set of values.
Case(value, [cases, ...])

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

  • value - Value to test.
  • cases - Cases to match.
When(value, result)

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

  • value - Value to match.
  • result - Result if matched.
Else(result)

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

  • result - Value if no match.

Date and Time Functions

These functions operate on date and time values.

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
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.
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.
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.
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.
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.
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.
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).
Day(date)

Gets the day component of a date/time value.

  • date - Date/time.
Month(date)

Gets the month component of a date/time value.

  • date - Date/time.
Year(date)

Gets the year component of a date/time value.

  • date - Date/time.
Hour(date)

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

  • date - Date/time.
Minute(date)

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

  • date - Date/time.
Today()

Today's date.

Now()

Today's date, including the current time.

Days(date1, date2)

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

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

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

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

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

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

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

  • date - 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).
HoursAndMinutes(minutes)

Expresses a quantity of minutes in hours and minutes.

  • minutes - Number of minutes.

Set Functions

These functions operate on sets of values.

Set([values, ...])

Creates a set from one or more values.

  • values - Values.
Range(set, [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.
Union(set1, set2)

Gets the union of two sets.

  • set1 - A set of values or assets.
  • set2 - A set of values or assets.
Except(set, 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.
Intersection(set1, set2)

Gets the intersection of two sets.

  • set1 - A set of values or assets.
  • set2 - A set of values or assets.
Sort(set, [smart = Yes])

Sorts the items in a set.

  • set - A set of values or assets.
  • smart - Whether to use natural language sorting rules.
RSort(set, [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.
NotEmpty(set)

Filters a set by excluding empty values.

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

Filters a set by excluding duplicate values.

  • set - A set of values or assets.
Each(set, expression)

Evaluates an expression for each item in a set.

  • set - A set of values or assets.
  • expression - Any expression.
First(set)

Takes the first item in a set.

  • set - A set of values or assets.
Last(set)

Takes the last item in a set.

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

Takes the n-th item in a set.

  • set - A set of values or assets.
  • position - Position of the desired item.
List(set, [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.
Join(set, [separator = ", "])

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

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

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

  • set - A set of values.
Paragraphs(set)

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

  • set - A set of values.
Count(set)

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

  • set - A set of values or assets.
CountNotEmpty(set)

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

  • set - A set of values or assets.

Contact Functions

These functions operate on contact assets.

SubjectivePronoun(contact)

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

  • contact - Contact.
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.

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

Resource(type, id)

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

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