Calculated properties are custom properties whose values are calculated from a formula. The formula can include the values of other properties, thereby creating dependencies between your properties. Library administrators can create calculated properties for all property types and in all types of library.
Before you use this article, you should:
- be familiar with the basics – learn more: Calculated properties: the basics
- know how to create and configure calculated properties in the library configuration
- be at ease with building simple formulas with copied code snippets – learn more: Getting started with formulas for calculated properties
- have experience adding entity references to your formulas and playing with entity references in JavaScript
- be familiar with the JavaScript programming language, conforming to the ECMAScript® 2019 specification
This article explains the JavaScript syntax you can use in each type of calculated property. It also provides examples of the corresponding calculated values you can expect.
Use this article alongside the article Create your own properties: play with entity references in JavaScript to learn how to be creative with your calculated properties according to your specific business needs.
Note about different types of JavaScript syntax
In the examples we give in our articles about calculated properties (learn more: Getting started with formulas for calculated properties), we use two types of JavaScript syntax:
- single expression
- multiple instructions, wrapped in an arrow function
You can use either in your calculated properties, but we recommended taking account of the following considerations.
General rule: the JavaScript code defining a formula must be made of one, and only one, expression.
This means that:
- if your logic can be expressed in a single expression, you can type it directly in the formula builder, for example:
property`Project name`+' - '+sequenceId`document`
- if your code requires additional instructions (such as when processing dates), you should wrap all your statements in an arrow function definition
(() => { ... })
, and call it right after the definition with an arrow function call()
:
(() => {
const d=new Date(property`Publication date`)
const yyyy=d.getFullYear(),
const mm=`${d.getMonth()+1}`.
const dd=`${d.getDate()}`.padStart(
return `${mm}/${dd}/${yyyy}`
})()
However, you can play with JavaScript to combine these multiple instructions into a single expression on a single line:
`${`${(new Date(property`Publication date`))
.getMonth()+1}`.
You can then enter this directly in the formula builder without using the arrow function definition.
We recommend using the arrow function definition because with the single-line expression:
- there's a lot of repetition, which is not good practice; in our example
new Date(property`Publication date`)
is repeated three times - the expression is long, which makes it difficult to read and debug
But it's your choice!
Calculated String or Text properties
String and Text properties accept as input:
- Strings
- Integers
- Decimals
- Booleans
They also support simple math calculations, which are evaluated when the formula is calculated and the result of which is displayed. Learn more: Use simple math calculations.
Below are some supported JavaScript expressions with their expected values.
JavaScript expression |
JavaScript type |
Value of calculated property |
Comment |
'Document validated' |
String |
Value: |
Single quotes |
"Document validated" |
String |
Value: |
Double quotes |
1234 |
Number |
Value: |
No formatting |
3.0 |
Number |
Value: |
No formatting |
1+2 |
Number |
Value: |
Evaluation first |
|
Boolean |
Value: |
English |
`${3+4} documents` |
String |
Value: |
String literal |
Calculated Integer properties
The nominal expected value is a JavaScript Number, but a best effort is made to also map String types.
Below are some supported JavaScript expressions with their expected integer values.
JavaScript expression |
JavaScript type |
Value of calculated property |
Comment |
|
Number |
Value: |
Nominal integer |
|
Number |
Value: |
Operation |
|
Number |
Value: |
No decimal part |
|
Number |
Value: |
Round-down |
|
Number |
Value: |
Round-down |
|
String |
Value: |
String parsing integer |
|
String |
Value: |
String parsing decimal |
Calculated Decimal properties
The nominal expected value is a JavaScript Number, but a best effort is made to also map String types.
Below are some supported JavaScript expressions with their expected decimal values.
JavaScript expression |
JavaScript type |
Value of calculated property |
Comment |
3.14 |
Number |
Value: |
Nominal decimal |
1.2+3.8 |
Number |
Value: 5 |
Operation |
4 |
Number |
Value: 4 |
Integer |
2 + 3.1 |
Number |
Value: |
Hybrid operation |
‘6.626’ |
String |
Value: |
String parsing decimal |
1 + 0.61 |
Number |
Value: |
Double precision: |
Calculated Boolean properties
The nominal expected value is a JavaScript Boolean, but a best effort is made to also map String types.
Below are some supported JavaScript expressions with their expected boolean values.
JavaScript expression |
JavaScript type |
Value of calculated property |
Comment |
true or false |
Boolean |
Value: |
Nominal |
‘true’ or ‘false’ |
String |
Value: |
String in english |
‘TRUE’ or ‘FALSE’ |
String |
Value: |
String in ENGLISH |
Calculated Date, Date&Time or Time properties
The nominal expected values are either JavaScript Date or Number. Strings are not supported.
Notes:
– Dates and times are given in Epoch milliseconds (the number of milliseconds since January 1, 1970, 00:00:00 UTC).
– Months in JavaScript start at zero: January is 0, February is 1, and so on. Learn more: Extract the month.
– Date properties must use a value that corresponds to midnight UTC, otherwise an error occurs.
– The display of dates varies according to the user's locale. For example, en_GB, en_US and fr_FR all display dates differently.
Below are some supported JavaScript expressions with their expected Date values.
JavaScript expression |
JavaScript type |
Value of calculated property |
Comment |
![]() |
Date |
AODocs Date property: |
JavaScript Date |
|
Number |
AODocs Date&Time property: Value: |
AODocs translates the number into a JavaScript Date |
|
Number |
AODocs Time property: Value: |
AODocs translates the number into a JavaScript Date |
|
Date |
AODocs Date&Time property: Value: Note: If you don't indicate time in the code, the time defaults to 12 AM UTC (or 12 AM UTC plus however many hours ahead of UTC your timezone is). |
JavaScript Date |
|
Date |
AODocs Date&Time property: Value: |
JavaScript Date |
Calculated Category properties
The nominal expected value is a String equal to the selected category value ID.
JavaScript expression |
Structure of the category value entity reference: For example:
Important: Use the code injector in the Formula pop-up. Learn more: Create calculated properties. |
JavaScript type |
String |
Value of calculated Category property |
Value: |