Calculated Fields

Was this article helpful?

You can use calculated fields to expand the data model using configured or captured data. For instance, you might want to fill calculated fields based on data captured in other fields.

Calculated fields allow you to write short scripts to extract any Clio Operate data. Using calculated fields is ideal for document generation or template administration. As well as extracting the data, you can perform basic operations on it, like comparing data, returning a value based on the comparison, and then formatting it. For example, you can calculate a participant's age and return this in words rather than numbers. You can also reference other calculated fields from within a field.

Using this page. Each tab covers one part of the work: setting up fields, writing expressions, looking up a function, working with lists, using fields in documents, script functions and debugging. To find a function or an operator, type in the Search the whole page box. It searches the tables on every tab at once. Above each table, use the dropdown to show one category.

🧭 Overview

Term Definition
Calculated field You can use expressions and scripts to reference, build, or retrieve data to use as a value.
Expression An expression is a function used to get a piece of data, like a claimant's last name.
Script A script is a series of expressions forming a more complex data retrieval and formatting function. For example, getting task completed dates from a matter and presenting them as a list in a document formatted with ordinals and the month name spelt out: the 3rd of March.

Creating a Calculated Field

Before you start

  • You need the core.modeller system permission to create, edit and delete calculated fields.
  • You can create calculated fields in any Data Composer explorer. For a work type, navigate to Modeller > Work Types > {Your WorkType} > Data Composer. For every place where Data Composer is available, see the article Data Composer.
  • Decide which level of the work type hierarchy to add the field at. Work types are hierarchical: to apply a field to a parent type such as 'matter' and all its child types, add it at the matter level. To use it on one work type only, add it to that work type.

Steps

Step Screen
1. Select the area in Data Composer where the field belongs, then select +. For example, to add a field to a work type, select Data Composer > Work Item, then select +.
The + button on Work Item in Data Composer
2. The calculated field blade opens. Enter a Name, a Display Name and a Description. You can also choose or create a Category (see Categorisation of Calculated Fields). The field is optional.
The new calculated field blade

Important note on the context of functions

If the Context card displays Work Item (as in the image above), write paths without workitem. at the start. For example, write roles.client.ods.person.lastName, not workitem.roles.client.ods.person.lastName.

A path that starts with workitem. does not produce an error. It returns an empty value, so counts return 0 and comparisons give a wrong answer. For example, count(workitem.roles.witness) returns 0 on a matter that has three witnesses. The examples in this article are written without the prefix.

 
3. Enter your expression. For help, see the Writing expressions and Functions tabs. Use the buttons below to browse the data, check the expression and test it.

4. Select Save or Save & Close.

If the work type has child types, the Cascade Changes dialog asks whether to apply the field to the child types too. Select Yes to add it to the child types, or No to add it to this work type only. The same dialog displays when you edit or delete the field. On a work type without child types, the field saves without the dialog.

Blade and editor buttons

Button Where What it does
Browse Ribbon Opens the Context Browser, which lists the data that you can use.
Debug Ribbon Opens the debugger (see the Debugging tab).
Delete Ribbon Deletes the field. Displays on a saved field only.
Save, Save & Close Ribbon Saves the field. Save & Close also closes the blade.
Close Ribbon Closes the blade.
icon with a green bug Debug Editor Opens the debugger, as the ribbon button does.
icon with a green circle containing a white question mark Help Editor Opens this article.
square icon with a green tick Validate Editor

Checks that the expression syntax is correct. If it is, the foot of the editor displays "Success!". Errors display at the foot of the window.

Validation checks the syntax only: a path that does not exist, or a typo such as x = x.name in place of x => x.name, still passes. Run the expression in the debugger to check the result.

A syntax error at the foot of the editor
icon with a green screen Toggle fullscreen Editor Switches the expression window between full-screen view and normal view.

If the editor displays a message about the Expression Engine version, see Expression Engine versions on the Writing expressions tab.

Finding and managing calculated fields

  • To find a field in Data Composer, search for its display name. The search does not match the system name.
  • To see every calculated field in the system, navigate to Modeller > Rules > Calculated Fields. The list displays each field's graph, name, display name, type, entity type, type path, and whether it is inherited or global.
  • To see the calculated fields of one work type, open its Data Composer and select View fields in the ribbon. The Calculated Fields blade lists each field's Name, Display Name, Description, On Type and Type Path.
  • On a work type that has a parent type, the ribbon also displays Copy fields from Parent. Select it, select the fields to copy, then select Confirm. Confirm is unavailable until you select a field.

Depending on where you add a field, the Context card of the calculated field blade can display two options:

Option Displays when What it does
Apply to this specific type of … The type can hold different kinds of entity. When selected, adds the field only to that kind of entity, for example a person.
Is global for all … types Fields can be global, for example on document templates. When selected, makes the field available to every type in that graph.

Deleting a calculated field does not ask you to confirm. The field is deleted when you select Delete, unless the work type has child types, in which case the Cascade Changes dialog displays first. Before you delete a field, check whether templates or other fields use it.

 

Adding a Calculated Field to a List

You can add a calculated field to a list by selecting the + button underneath the filter for the list. One use for this is adding calculated values to a list or displaying parent information in a list. For more information, see the article Calculated Lists.

The field is added to the type that the list contains, not only to that list. For example, a field that you add from a list of children is added to every Work Item Base, and the blade displays "This calculated field will be added to all instances of Work Item Base."

When you create a calculated list, for example with the + button on a list such as Participants, the blade displays a Sort By card. To sort the list:

  1. Select + on the Sort By card.
  2. Select a field in the Context Browser.
  3. Choose Ascending or Descending.

To sort by more than one field, add more fields. Without a sort field, the list keeps the order of the list that it is based on.

Categorisation of Calculated Fields

If you have many calculated fields in your system, you can organise them by creating categories and assigning fields to the categories. 

Use the Category drop-down to assign a field to a category. To create a category, enter a new name and select Add new category. Data Composer lists each category's fields under their own heading.

The following video shows this in practice:

 
 

✏️ Writing expressions

Operators & Keywords

The following is a list of the operators and keywords you can use when creating calculated fields.

Rules for writing expressions

  • Put a space on both sides of an operator. Without spaces, a hyphen becomes part of a field name: reference-1 is read as a field called reference-1.
  • Enclose text in straight single quotes, e.g. 'hello world'. Curly quotes (‘ ’) cause a syntax error.
  • Use square brackets only for lists, e.g. [313081,31002,31003]. [title] is read as a list that contains the title.
  • Function names are not case-sensitive: format, Format and FORMAT all work.
  • The arithmetic operators have equal priority and are worked out from left to right, so 2 + 3 * 4 returns 20. Use brackets to control the order. See Mathematical Calculations on the Functions tab.
 

Use the dropdown to filter by category, or type in the search box to narrow results further.

Examples 

Operator

Example

= 

subtype.id = 31003

Tests whether the work item's sub-type has an ID of 31003.  

Returns True if a match is made. 

In 

subtype.id in [313081,31002,31003]

Tests whether the sub-type is any one of the three values. 

Returns True if a match is made. 

> 

count(roles.buyer) > 1

There is more than one Buyer on the property transaction. 

Returns True if a match is made. 

+ 

roles.buyer!1.ods.person.firstName + ' ' + roles.buyer!1.ods.person.lastName

Returns the first buyer's name, e.g. "Joe Bloggs". 

Add the two fields together, with a space in between. 

Using Fields with Special Characters

When a field's query string contains special characters, you must ‘escape’ those characters for the query to be valid. For example, the following query string raises an error:

financialTransactions!q?code=CLIENT;REC;DEBTPRINCIPLE&transactionTypes=invoice&total=true.amount

The error is similar to: Syntax error (line 1, column 36): unexpected `;`.

Escape each semicolon with a backslash:

financialTransactions!q?code=CLIENT\;REC\;DEBTPRINCIPLE&transactionTypes=invoice&total=true.amount

Data Composer Tags in Expressions

When using tags in an expression, you can use the 'local' name of a field.

For example, in a calculated field that you add to the phase of a work type, you can refer to the phase name as either workitem.phase.name or name.

 

When using data composer tags in expressions, you can move through the data hierarchy:

Operator / Keyword Description
$root Takes you to the top of the data. Follow it with workitem. in a work item field, or context. in a document, e.g. $root.workitem.parent.reference.
$parent Moves one step up the field's own data path. Repeat it to move up further. For example, for a field on Work Item > Roles > Claimant, $parent.$parent.reference returns the work item's reference.
parent. The parent work item. Only its basic fields are available, e.g. reference, title, type, phase, and sub-type: parent.reference.
ancestors All the work items above this one. Use a query to choose one and to reach its participants and other data, e.g. ancestors!q?path=matter!1.roles.claimant!1.ods.name.

$root and $parent return empty values inside a lambda function. To use a value inside a lambda, put it in a variable first:

var today = $root.env.now.utc.value;
roles.claimant.select(x => x.ods.name + ' ' + dateDiff(x.ods.person.dateOfBirth, today, 'y'))

Comments

You can add comments to an expression. Clio Operate ignores comments when it runs the calculated field. Use them to explain parts of an expression, or to stop work in progress from running while you test.

Start a comment with /* and end it with */. The editor displays comments in green text. A comment can be on one line or span several lines. Comments are available in version 2 only.

For example, this comment explains the expression that follows it:

/* Add 10 days to today */
format(dateAdd('d', 10, $root.env.now.utc.value), 'dd MMM yyyy')

This comment stops part of an expression from running while you test:

/*
 Work in progress:
 dateAdd('y', 1, $root.env.now.utc.value)
*/
reference

Expression Engine versions

Calculated fields run on a versioned expression engine. When Clio Operate makes a major change to the engine, it releases a new version of it and keeps the earlier versions available. Each calculated field stores the version it was written against, so it is always evaluated against the grammar it was built for. New fields use the latest version. The Version field displays above the expression editor only when a field uses an older version.

If a field is on an older version, the calculated field blade displays the message "The latest expression engine version is not being used. Upgrade by changing the version in the dropdown below."

This message is informational. It does not mean the field is broken, and it does not mean the field will stop working. The only practical difference is that a field left on an older version cannot use what later versions add.

Compare version 1 and version 2

New fields use version 2. The table lists what each version supports.

Feature Version 1 Version 2
Arithmetic (+ - * /), comparisons, and, or Yes Yes
Functions, such as format(…) and if(condition, a, b) Yes Yes
if … then … else No. Use if(condition, a, b). Yes
The % operator No Yes
not, in and not in No Yes
Lists in square brackets, e.g. [1, 2, 3] No Yes
Spread (...) No Yes
Lambda functions (=>), e.g. select, where, any No Yes
var and ; No Yes
Comments (/* … */) No Yes
Reserved words and, or, true, false, null Also if, then, else, not, in, var

Upgrading a field

To upgrade a field, select a newer version in the Version field, then select Save.

Upgrading recompiles the expression under the newer grammar. This is low risk for the majority of expressions, but check the following before you save:

  • Later versions reserve additional keywords. Version 1 reserves and, or, true, false and null. Version 2 also reserves if, then, else, not, in and var. An expression that references a field named after a reserved keyword needs a small change before it validates.
  • Validate the expression after changing the version. Any errors display at the foot of the editor.
  • Run the field against a real work item in the debugger and confirm the result matches the result from the previous version.

Upgrading multiple fields

There is currently no bulk upgrade option. Upgrade each calculated field individually from its expression editor. 

 
 

🔣 Functions

Common Functions

The following is a list of commonly used functions that you can use to build up your expressions within calculated fields.

In the table below, the function parameter my_field refers to the field against which you run the function. A comma separates any further parameters, and function parameters are enclosed in brackets.

You can find a list of Culture Codes here: Supported Culture Codes. 

To find a function, type in the Search the whole page box above the tabs, or use the dropdown above the table to show one category. To copy a link to a function, hover over its row and select the link icon in the first cell.

To list every function while you write, press Ctrl+Space in the expression editor:

The function list in the expression editor

Use the dropdown to filter by category, or type in the search box to narrow results further.

 
 

📋 Lists and lambdas

Advanced Calculated Fields

Lambda functions work on lists, such as the participants in a role. Each one takes a short function, written x => …, and applies it to every item: select changes each item, and where keeps the items that match. The result is often joined into one value, for example a comma-separated list of names for an email or a document.

For example, you can select the occupiers of a sale property who are over 18 and join their names into one string, or list all the payments made between two dates.

Things to know

  • Lambda functions work in version 2 only. See Compare version 1 and version 2 on the Writing expressions tab.
  • filter is an alias of where: they do the same thing.
  • A lambda can also take the position of each item in the list, starting at 0, e.g. roles.witness.select((x, i) => i + ': ' + x.ods.name) returns 0: Nathan Witness, 1: Wendy Witness, 2: Andrew Witness.
  • You can split a long expression over several lines, with one function per line. These two expressions are the same:
roles.claimant.select(x => x.ods.name)
roles.claimant
.select(x => x.ods.name)

Use the dropdown to filter by category, or type in the search box to narrow results further.

Roles that hold one participant

Some roles, such as Client and Claimant Litigation Friend, hold one participant. For these roles, the path returns one participant instead of a list: roles.client.ods.name and roles.client!1.ods.name return the client's name, but count(roles.client) returns 0 and roles.client.select(…) returns an empty item.

To use one of these roles in a list function, put its value in square brackets, e.g. [roles.client.ods.name].

 
 
 

📄 Documents

Display Rules with Lambda Functions

Lambda functions can also be used in Display Rules in the ShareDo Word Plugin. The function returns a true or false result, which then shows or hides a Tag, Section or Content Block in the generated document.

Scenario

A Prepare Document template presents the user with an Option Set containing two entries: Tenancy Documents and Title Documents.

Display Rules are required to handle each combination of selection, so that the relevant Sections appear in or are hidden from the generated document.

In this example (option set value IDs are different in each environment, so check the IDs in your option set):

  • The Option Set ID for Tenancy Documents is 500001914.
  • The Option Set ID for Title Documents is 500001915.

Each of these display rules returns true when the user makes that selection:

The user selected Display rule
Tenancy Documents only
document.questionnaire.tenancyOrTitleDocuments.count() = 1
and
document.questionnaire.tenancyOrTitleDocuments!1.id = 500001914
Title Documents only
document.questionnaire.tenancyOrTitleDocuments.count() = 1
and
document.questionnaire.tenancyOrTitleDocuments!1.id = 500001915
Both options
document.questionnaire.tenancyOrTitleDocuments.any(x => x.id = 500001914)
and
document.questionnaire.tenancyOrTitleDocuments.any(x => x.id = 500001915)
Exactly one option
document.questionnaire.tenancyOrTitleDocuments.count() = 1

Testing display rules

The Word plugin checks the syntax of a display rule, not its paths. If a path is wrong, the rule returns false and the content is hidden without an error. Clio recommends that you test every display rule by generating a document against a real work item. If a rule cannot be evaluated, the generated document displays an error in red, e.g. "Error evaluating the display rule 'Recipient is client' for this control."

Do not use pluck in a display rule. To check a list of values, use any, or select with contains:

document.recipient.contextRoles.any(x => x.roleType.systemName = 'client')
contains(document.recipient.contextRoles.select(x => x.roleType.systemName), 'client')

Calculated Fields in Documents

A document template reads data through three starting points:

Starts with What it reads Example
context. The work item that the document is for, including its calculated fields. A calculated field that you add to Work Item is available as context. followed by the field name. context.reference
document. The document itself, including the questionnaire answers and the recipient. The recipient's roles on the work item are at document.recipient.contextRoles. document.questionnaire.weekly_pay_amount.value
document.recipient.ods.name
env. The environment. env.now.utc.value

Documents do not have a workitem. path: use context. instead. Form Builder dates appear in documents as stored, e.g. 12/09/2023.

Litigation Parties

Courts commonly require that all parties in a particular Role (e.g. claimant, defendant) are presented in a list comprising their name, their "ordinal" (e.g. First Claimant, Second Claimant, Third Claimant, etc.) and their address.  

For example, a list of all claimants on a Proceeding:

(FIRST) Peter Thompson, Lock Keepers Cottage, Basin Road, Worcester, Worcestershire, WR5 3DA; (SECOND) William Smith, 2 Oxbridge Close, Sale, Greater Manchester, M33 5XJ and (THIRD) Fred Jones, 1 The High Street, Hale Barns, Altrincham, Greater Manchester, WA15 0WU.

Note the final 'and' between the second and third claimants' details. The replaceLast step in the expression below adds it.

If only one participant holds a role, courts often ask that their ordinal is not presented. For example, if more than one defendant is party to proceedings, use "FIRST Defendant", "SECOND Defendant", and so on. Otherwise, present "Defendant".

All of the above can be achieved using the following expression:

if count(roles.claimant) > 1 then
  roles.claimant.select(x =>
   '(' + x.roleOrder.ordinal.toUpper() + ') ' +
   x.ods.name + ', ' +
   x.locations.5002500.formattedCsv)
  .join('; ')
  .replaceLast('; ', ' and ')
else
  roles.claimant!1.ods.name + ', ' +
  roles.claimant!1.locations.5002500.formattedCsv

roleOrder.ordinal returns First, Second, Third, and so on. locations.5002500 is the participant's correspondence address. If a participant has no correspondence address, the text keeps the comma after the name.

The following expression will return all claimants and their roles on a new line.

if count(roles.claimant) > 1 then
  roles.claimant.select(x =>
  x.roleOrder.ordinal.toUpper() + ' Claimant: ' + x.ods.name)
  .join('\n')
else
  'Claimant: ' + roles.claimant!1.ods.name + ', ' + roles.claimant!1.locations.5002500.formattedCsv

For example:

FIRST Claimant: Peter Thompson
SECOND Claimant: William Smith
THIRD Claimant: Fred Jones

In a generated document, the lines are line breaks within one paragraph, not separate paragraphs.

 
 

🧩 Script functions

User-Defined Script Functions

User-defined script functions are functions which can be written to perform a specific task. Expressions can reference these functions, pass values to them, and receive the resulting data. Storing these functions centrally and calling them only when required ensures uniformity/standardisation and saves rewriting the same script into every expression where a specific task is required.

For example, a function can be scripted to convert a date into a specific format. Rather than write this code into every expression that requires a date to be formatted, a single user-defined function can be called, and the date passed to the function for formatting.       
The Script Functions editor is available via Modeller > Rules > Script Functions.

You need either the core.modeller or the core.adminAccess system permission to manage script functions.

Script Function Examples

This example creates a function that replaces the +44 prefix of a UK telephone number with 0.

Step Screen
1. Select New to create a script function. The script function editor opens.
Script function editor
2. In the Field section, enter a name and a description for the function. The name cannot be the same as a built-in function, such as sign: the editor displays "sign is a reserved identifier and cannot be used".  
3. Select + to add a parameter. Parameters set which values a calculated field can pass to the function, for example a date to format.  
4. Enter a Name for the parameter, for example ParticipantNames or IncidentDate. This example uses telephoneNo. Leave Default Value and Optional as they are: the next example uses them.
Parameters using a telephoneNo

5. Write the expression. The editor works like the calculated field editor, except that the parameter name holds the value that a calculated field passes in. This example uses:

replace(telephoneNo, '+44 ' , '0')

If the telephone number in telephoneNo contains +44 followed by a space, the prefix is replaced with 0.

 
6. Save the function. It is added to the list of script functions.  

Using the new function

To use the function in a calculated field, call the function and pass the field name to be formatted. For example:

RemoveUKCountryCode(roles.claimant!1.ods.contact.direct-line!q?primary=true.value)

When run, the claimant's direct-dial telephone number will have its prefix of '+44 ' replaced with a '0'. If you call a function without a required parameter, validation displays an error, e.g. "requires 1 argument(s)".

A more complex example

This example adds two parameters to a function, and uses the Default Value field and the Optional toggle.

This function removes all country codes, not just the UK's.

As before, create a new function called RemoveCountryCode, with these parameters:

Parameter Optional Default value Purpose
telephoneNo Off, so the parameter is mandatory None The telephone number.
prefix On '+44 ' The country code to replace. If the call does not pass a prefix, the function uses the default value.

The expression is as follows:

replace(telephoneNo, prefix, '0')

It works like this: take the telephone number and look for the value passed in the prefix parameter. If this is not passed, use the default '+44 '. Replace the prefix value with a 0. For example, RemoveCountryCode(roles.claimant!2.ods.contact.direct-line!q?primary=true.value, '+61 ') turns +61 400 123 456 into 0400 123 456.

The result is a generic function. Pass any international country code as the second parameter, or leave it out for a UK number.

In a calculated field, call the function as follows:

RemoveCountryCode(roles.claimant!1.ods.contact.direct-line!q?primary=true.value)

Formatting a date in German

This function converts a date to German display format, for example, 13. März 2026.

Create a new function called ConvertGermanDateFormat with a single mandatory parameter, thedate.

Add the following expression:

format(thedate, 'dd. MMMM yyyy', 'de-DE')

The German culture code de-DE makes format use German month names, so the expression returns the day, the German month name, and the year.

To use the function in a calculated field, call it and pass the field to be formatted:

ConvertGermanDateFormat(oralHearingDate)

If oralHearingDate holds 13 March 2026, the function returns 13. März 2026.

Deleting Script Functions

You cannot delete a function while expressions use it. To delete a function, open it and select Delete in the ribbon. The Find Usages panel lists where the function is used.

The Find Usages panel, with a Manage icon next to each usage

Select the Manage icon (a cog) next to a usage to open it, and remove the function from that expression. Then select Refresh: the panel displays "No usages found."

Delete stays unavailable until no usages remain. Select Delete and confirm. The delete is permanent and cannot be undone.

 
 

🐞 Debugging

Debugging Expressions

Select either the Bug icon or the Debug button to open the Debugger. The debugger runs the expression without saving the field.

Button What it does
Run Runs the expression against the selected work item, or against data that you enter. See Testing Expressions.
Browse

Opens the Context Browser for the selected work item. To copy a tag name, navigate to the tag and select the copy icon, then paste it into the expression editor.

tag with a green copy icon

Functions Opens the Script Functions list, which shows the script functions that you can call. See the Script functions tab.
Save Closes the debugger and passes the expression, with any changes that you made, back to the calculated field blade. Save the field to keep the changes.
Cancel Closes the debugger without passing any changes back.

To choose how to find a work item, select the arrow next to the search box. The debugger does not check that the work item matches the field's work type, so choose a work item of the right type.

Choosing a work item

Option How to use it
Quick Search

In the search box at the top left, enter a keyword from the work item, e.g. part of the client's name, the matter reference or a participant name. Select the work item in the list of matches.

List of work items matching the search

Advanced Search Select the Select… box to open the advanced search. You can search by reference, title, type, dates, owner or participant. Select the work item, then select Confirm.
Manual Entry Enter the unique ID of the work item.

Testing Expressions

Step Screen
1. Choose a work item (see Choosing a work item), then select Run. The debugger runs the expression against that work item.  
2. Check the left-hand console. The console lists any data referenced by the expression.
The left-hand console listing the data that the expression references
3. Check the green panel at the foot of the form. The panel displays the expression results.
The green results panel

For example, if an expression formats a key date, the console displays the date as it is stored:

The results panel displays the result of the expression, which is the formatted date:

You can also test an expression against data that you enter yourself. Without a work item, the debugger uses the JSON in the left-hand console. With entered data, the ! index (e.g. !1) does not work: use .select(…).elementAt(0) instead.

 
 

Was this article helpful?

Related articles

Related articles in the knowledge base