Calculation
Reference documentation for a Calculation object
Last updated
Reference documentation for a Calculation object
Last updated
A Calculation object provides a dynamic, calculated value in a Table in a Database Server. A calculation is a JavaScript function, which is always computed on-demand, whenever it is displayed or referenced in code. It can be added to the UI the same as any other Data Provider. A calculation is read-only
.
The code for a Calculation is stored in a script file in a Solution directory -> "datasources" directory -> "table-name" directory. The file has the same name as the table "_calculation", with a .js
extension. For example, the products
table would have the calculation file products_calculation.js
.
Nesting file path: "solution/datasources/server-name/table-name/table-name_calculations.js"
The following properties can be set for a Calculation object.
Property | Summary |
---|---|
The name of the calculation. It is also the same name as the function that returns the value.
The data type of the object that will be returned from the calculation. All data types are generalized to one of five standard types:
This is the JavaScript function that defines the calculation. It takes no arguments and should return a value. Other data providers from this table, related data sources, and scope variables can be used.
Example
A calculation is said to be stored when a physical column with the same name exists on the table. The real column can be updated opportunistically when a calculation runs.
Stored calculations can be unpredictable, there is no guaranteed way to know exactly when they will run to update the underlying column in the table, especially if they are complex or depend on other calculations or methods.
A better approach is to use to catch changes to the table and make updates to other columns if necessary.
The name of the calculation. It is also the same name as the function that returns the value.
The data type of the object that will be returned from the calculation
This is the JavaScipt function that defines the calculation.
A calculation is said to be stored when a physical column with the same name exists on the table