With AODocs, you can set up conditional logic in document classes in any type of AODocs library. When users edit their documents, conditional logic is applied as follows:
- property values can be calculated automatically
- properties can be conditionally mandatory or hidden
- document titles can be calculated automatically (in Document Management libraries only)
Conditional logic is calculated using formulas that can include references to other entities such as custom or system properties, property states (mandatory or hidden) and the document title.
Before you use this article, you should:
- be familiar with the basics – learn more: What is conditional logic in AODocs?
- know how to set up conditional logic in the library configuration to:
This article explains how to implement simple use cases with code examples you can copy. Use this article alongside the article Add entity references to your formulas to build simple formulas.
Advanced users can get creative and write their own formulas for conditional logic:
- Create your own formulas: play with entity references in JavaScript
- Create your own formulas: use the correct JavaScript syntax for conditional logic
Learn how to create formulas:
Automatically generated table of contents
Before you start
This article describes how to create some simple formulas for conditional logic. You can use existing AODocs entities in your formulas. Learn more: What can I use in my formula?
A block of text formatted like this and containing the name of your property is inserted into your formula:
propertyString`Document type`
This block of text is called an entity reference. If you copy the examples provided in this article, make sure you don't select the entity references. When you insert your own properties into your formulas, unique entity references are generated, containing the names of your properties.
Create a unique document sequence ID
What is the sequence ID?
In AODocs, each version of a document is given a set of four numbers, composed of the following:
-
Library sequence ID
The first library created in your domain has the library sequence ID1
, the second has2
, etc. -
Document class sequence ID
The first document class in a library has the document class sequence ID1
, the second has2
, etc. -
Document sequence ID
The first document created in a document class has the document sequence ID1
, the second has2
, etc. -
Version sequence ID
The first version of a document has the version sequence ID1
, the second version has2
, etc.
For example, the full sequence ID 34, 3, 897, 2
corresponds to the 2nd version of the 897th document of the 3rd class of the 34th library in the domain.
Important:
– Full sequence IDs are unique per document version within a domain.
– Sequence IDs are generated sequentially. However, if an error occurs, a given number may be skipped.
– Sequence IDs are generated when you create your document class, document, or version. The constantly increasing sequence IDs don't take account of any classes, documents or versions you permanently delete.
Sequence IDs are useful because they allow you to generate unique IDs that you can use to reference your documents. For example, you can save the document sequence ID in a calculated property value or title. This gives you automatically generated and easily accessible document references.
You can use library, document class and document sequence IDs in formulas for conditional logic.
Important: They are String type entities.
Create a sequence ID for all document titles in a document class
Use case: generate a unique ID per document within a document class to use as calculated titles.
1. Configure conditional logic to calculate document titles for a document class in a Document Management library.
2. In the lower left panel of the formula builder, click Sequence ID. The list of sequence IDs is displayed in the right panel. Click the Insert button next to Document sequence ID. A simplified entity reference is inserted into the body of the formula:
sequenceId`document`
Optional:
If you want a document sequence ID with a specific number of digits, add .padStart(5,'0')
to the end of your formula:
sequenceId`document`.padStart(5,'0')
where 5
is the number of digits you want.
Create a document sequence ID with a fixed prefix
Use case: Give the prefix "SOP" to all the document sequence IDs of your "Standard Operating Procedure" document class.
1. Create a new String type property. Name it "Document ID", for example.
2. Set up conditional logic to calculate its values. First add this to the formula:
'SOP'+' - '+
3. In the lower left panel of the formula builder, click Sequence ID. The list of sequence IDs is displayed in the right panel. Click the Insert button next to Document sequence ID. A simplified entity reference is inserted into the body of the formula:
'SOP'+' - '+sequenceId`document`
Optional:
If you want the number part of the document sequence ID to have a specific number of digits, add .padStart(5,'0')
to the end of your formula:
'SOP'+' - '+sequenceId`document`.padStart(5,'0')
where 5
is the number of digits you want.
Create a document sequence ID with a prefix issued from a String property
Use case: Make all the document sequence IDs of your "Project" document class start with the value of the "Project name" property (type String).
Example of the final formula:
propertyString`Project name`+' - '+sequenceId`document`
Configure conditional logic to calculate property values
1. Create a new String type property. Name it "Document ID", for example.
2. Set up conditional logic to calculate its values: in the lower left panel of the formula builder, open the Properties list under From document. Select String / Text in the list. Then click Insert next to the required String property in the right panel (in our example, "Project name"). A simplified entity reference like this is inserted into the body of the formula:
propertyString`Project name`
3. Add this to the formula:
+' - '+
4. In the lower left panel of the formula builder, click Sequence ID. The list of sequence IDs is displayed in the right panel. Click the Insert button next to Document sequence ID. A simplified entity reference is inserted into the body of the formula:
propertyString`Project name`+' - '+sequenceId`document`
Optional:
If you want the number part of the ID to have a specific number of digits, add .padStart(5,'0')
to the end of your formula, where 5
is the number of digits you want.
Important: If there is no value in the String type property ("Project name" in our example), its entity reference is replaced with null
in the calculated property value. You can write this formula to replace the entity reference by a value of your choice ("Default", in our example): (propertyString`Project name` ? propertyString`Project name` : 'Default') +' - '+sequenceId`document`
For example:
Create a document sequence ID with a prefix issued from a Category property
Use case: Make all the document sequence IDs of your "Document" document class start with the value of the "Document type" property (type Category).
Note: This formula only works with mono-value, single-level properties. Learn more: What are categories?
Example of the final formula:
propertyCategory`Document type`.name +' - '+sequenceId`document`
1. Create a new String type property. Name it "Document ID", for example.
2. Set up conditional logic to calculate its values: in the lower left panel of the formula builder, open the Properties list under From document. Select Categories in the list. Then click Insert next to the required category in the right panel (in our example, "Document type"). A simplified entity reference like this is inserted into the body of the formula:
propertyCategory`Document type`
3. Add this to the formula:
.name +' - '+
4. In the lower left panel of the formula builder, click Sequence ID. The list of sequence IDs is displayed in the right panel. Click the Insert button next to Document sequence ID. A simplified entity reference is inserted into the body of the formula:
+sequenceId`document`
Optional:
If you want all the sequence IDs of your "Document" document class to start with the short name of the value of the "Document type" property category, replace .name
by .shortName
(case sensitive). Final result:
propertyCategory`Document type`.shortName +' - '+sequenceId`document`
If you want the number part of the document sequence ID to have a specific number of digits, add .padStart(5,'0')
to the end of your formula:
propertyCategory`Document type`.shortName +' - '+sequenceId`document`.padStart(5,'0')
where 5
is the number of digits you want.
Important: If there is no value in the Category property, an error occurs when the formula is calculated, preventing the document from being saved – learn more: Handle errors in conditional logic. Use this formula to replace the category's entity reference by a value of your choice ("No doc type" in our example):((propertyCategory`Document type` && propertyCategory`Document type`.name)
? propertyCategory`Document type`.name : 'No doc type')+" - "+sequenceId`document`
For example:
Create a document sequence ID prefixed with the document creation year
1. Create a new String type property. Name it "Document ID", for example.
2. Set up conditional logic to calculate its values using the following formula:
new Date(systemPropertyDateTime`creationDate`).getFullYear()+' - '+sequenceId`document`
Optional:
If you want the number part of the ID to have a specific number of digits, add .padStart(5,'0')
to the end of your formula, where 5
is the number of digits you want.
Use a date with a specific format
Use a Date system property with the format YYYY/MM/DD
Use case: Use the document creation date in calculated property values with the following format: YYYY/MM/DD
Final formula:
(() => {
const d=new Date(systemPropertyDateTime`creationDate`)
const yyyy=d.getFullYear()
const mm=`${d.getMonth()+1}`.padStart(2,'0')
const dd=`${d.getDate()}`.padStart(2,'0')
return `${yyyy}/${mm}/${dd}`
})()
Use a Date custom property with the format MM/DD/YYYY
Use case: Use the value of the "Publication date" property in calculated property values with the following format: MM/DD/YYYY
Example of the final formula:
(() => {
const d=new Date(propertyDate`Publication date`)
const yyyy=d.getFullYear()
const mm=`${d.getMonth()+1}`.padStart(2,'0')
const dd=`${d.getDate()}`.padStart(2,'0')
return `${mm}/${dd}/${yyyy}`
})()
1. Create a new String type property. Name it "Formatted publication date", for example.
2. Set up conditional logic to calculate its values. First add this to the formula:
(() => {
const d=new Date(
3. In the lower left panel of the formula builder, open the Properties list under From document. Select Date / Time in the list. Then click Insert next to the required Date property in the right panel (in our example, "Publication date"). A simplified entity reference like this is inserted into the body of the formula:
propertyDate`Publication date`
4. Write the rest of the formula:
)
const yyyy=d.getFullYear()
const mm=`${d.getMonth()+1}`.padStart(2,'0')
const dd=`${d.getDate()}`.padStart(2,'0')
return `${mm}/${dd}/${yyyy}`
})()
Calculate a "next review" date
This formula lets you to generate a date in calculated property values from another date property to which a given number of months is added.
Calculate a "next review" date as a fixed period after the "Application date"
Use case: Calculate a "next review" date, 12 months after the "Application date".
Example of the final formula:
(() => {
var date = new Date(propertyDate`Application date`);
date.setMonth(date.getMonth()+12);
return date;
})()
1. Create a new Date type property. Name it "Next review date", for example.
2. Set up conditional logic to calculate its values. First add this to the formula:
(() => {
var date = new Date(
3. In the lower left panel of the formula builder, open the Properties list under From document. Select Date / Time in the list. Then click Insert next to the required Date property in the right panel (in our example, "Application date"). A simplified entity reference like this is inserted into the body of the formula:
propertyDate`Application date`
4. Write the rest of the formula:
);
date.setMonth(date.getMonth()+12);
return date;
})()
Calculate a "next review" date as "Review period" (number of months) after the "Application date"
Use case: Generate a "next review" date calculated from the number of months in the "Review period (in months)" property after the "Application date".
Example of the final formula:
(() => {
var date = new Date(propertyDate`Application date`);
date.setMonth(date.getMonth()+propertyInteger`Review period`);
return date;
})()
1. Create a new Date type property. Name it "Next review date", for example.
2. Set up conditional logic to calculate its values. First add this to the formula:
(() => {
var date = new Date(
3. In the lower left panel of the formula builder, open the Properties list under From document. Select Date / Time in the list. Then click Insert next to the required Date property in the right panel (in our example, "Application date"). A simplified entity reference like this is inserted into the body of the formula:
propertyDate`Application date`
4. Add this to the formula:
);
date.setMonth(date.getMonth()+
5. In the lower left panel of the formula builder, open the Properties list under From document. Select Number in the list. Then click Insert next to the required Number property in the right panel (in our example, "Review period"). A simplified entity reference like this is inserted into the body of the formula:
propertyInteger`Review period`
6. Write the rest of the formula:
);
return date;
})()
Calculate a duration between two dates
Use case: Calculate how many days between the "Start Date" and "End Date", defined in your document as Date type properties.
Note: The value calculated can be negative.
Example of the final formula:
(() => {
var startDate = new Date(propertyDate`Start Date`);
var returnDate = new Date(propertyDate`End Date`);
return (returnDate.getTime() - startDate.getTime()) / (1000 * 3600 * 24);
})()
1. Create a new Integer type property. Name it "Duration (in days)", for example.
2. Set up conditional logic to calculate its values. First add this to the formula:
(() => {
var startDate = new Date(
3. In the lower left panel of the formula builder, open the Properties list under From document. Select Date / Time in the list. Then click Insert next to the required Date property in the right panel (in our example, "Start date"). A simplified entity reference like this is inserted into the body of the formula:
propertyDate`Start Date`
4. Add this to the formula:
);
var returnDate = new Date(
5. In the lower left panel of the formula builder, open the Properties list under From document. Select Date / Time in the list. Then click Insert next to the required Date property in the right panel (in our example, "End date"). A simplified entity reference like this is inserted into the body of the formula:
propertyDate`End Date`
6. Write the following at the end of the formula:
);
return (returnDate.getTime() - startDate.getTime()) / (1000 * 3600 * 24);
})()
Use workflow states to calculate property values
Use case: Record the date when your document is published. The date your document transitions to the “Published” workflow state is recorded in a calculated Date property called "Publication Date".
When you save your document, if its workflow state is:
- “Published” – the system property "stateChangeDate" is updated with the current date (date of the transition to "Published"), and the value of this system property is recorded as the value of the property "Publication Date"
- not “Published” – the property "Publication Date" is not recalculated
Note: The property "Publication Date" is empty if the document has never been published.
Example of the final formula:
systemPropertyString`stateId` === state`Published`
? new Date(new Date(systemPropertyDateTime`stateChangeDate`).getFullYear(), new
Date(systemPropertyDateTime`stateChangeDate`).getMonth(), new
Date(systemPropertyDateTime`stateChangeDate`).getDate())
: propertyDate`Publication Date`
1. Create a new Date type property. Name it "Publication Date", for example.
2. Save your property so you can self-reference it later. To do this, add ""
to the formula builder and save, then reopen the formula builder.
3. Set up conditional logic to calculate the values of your new property.
First add this to the formula:
systemPropertyString`stateId` ===
4. In the lower left panel of the formula builder, select Workflow states under From library. Then click Insert next to the required workflow state in the right panel (in our example, "Published").
5. Add this to the formula:
? new
Date(new Date(systemPropertyDateTime`stateChangeDate`).getFullYear(), new Date(systemPropertyDateTime`stateChangeDate`).getMonth(),
new Date(systemPropertyDateTime`stateChangeDate`).getDate())
:
6. In the lower left panel of the formula builder, open the Properties list under From document. Select Date in the list. Then click Insert next to the required Date property in the right panel (in our example, "Publication"). A simplified entity reference like this is inserted into the body of the formula:
propertyDate`Publication Date`
Important: Make sure you use the exact name of the workflow state, not the name of the user action used to run the workflow transition to the workflow state. Learn more: Create workflow states.
Calculate the value of a category from another manually-filled category
You want to calculate the value of a Category property called "Language".
Use a simple mapping rule to determine the value of the calculated Category property, based on the value of another Category property called “Country“ that is manually filled in:
- if "Country" is "Mexico" or "Spain", the language should be "Spanish"
- otherwise, the language should be "English"
Formula:
(propertyCategory`Country`?.id === categoryValue`Country:Mexico(UQsog8K000001WNCCz)` ||
propertyCategory`Country`?.id === categoryValue`Country:Spain(Rppdjyq0pAfD4dYDJS)`)
? categoryValue`Language:Spanish(UQsrfCy000001pwOLe)`
: categoryValue`Language:English(UQsrhys000001Cug8A)`
where:
-
categoryValue`Country:Mexico(UQsog8K000001WNCCz)`
(on line 1) refers to the category value "Mexico" of the category defined at the library level and used in the "Country" property -
categoryValue`Country:Spain(Rppdjyq0pAfD4dYDJS)`
(on line 2) refers to the category value "Spain" of the category defined at the library level and used in the "Country" property
and
-
categoryValue`Language:Spanish(UQsrfCy000001pwOLe)`
(on line 3) refers to the category value "Spanish" of the category defined at the library level and used in the "Language" property -
categoryValue`Language:English(UQsrhys000001Cug8A)
(on line 4) refers to the category value "English" of the category defined at the library level and used in the "Language" property
Use simple math calculations
Use cases:
- Calculate the total price of a commercial proposal, for example:
- number of days × daily rate
- number of pieces × price per piece
- Calculate the VAT with a fixed tax percentage
- Calculate the VAT with a tax percentage written in another property
It's easy to write math calculations in the formulas of properties with calculated values. You can use the standard operators: +, -, *, /
To use Number type properties (Integer or Decimal), click the property name in the left panel of the formula builder, under Integer or Decimal. When you do this, a simplified entity reference like this is inserted in the body of the formula:
propertyDecimal`Daily rate`
The formula of a sum between two properties looks like this:
propertyInteger`Duration of the service` + propertyInteger`Travel time`
If you need to use fixed numbers, simply write them in the formula:
0.2 * (propertyDecimal`Cost price` - propertyDecimal`Reduction`)