Formula
Description
You can create fields that are calculated instead of being entered by
the user. These fields are called the formula fields. When you create
a formula field, you have to specify the formula expression based on which
the value for this field is calculated. Depending on the output of the
formula, the value held by a formula field could be numeric values, text
values, dates, and durations. The formula evaluation is nothing but expression
evaluation and is explained in detail in Expressions.
Example: In the below given sample, the field TotalMarks is of
type formula, English and Maths are the fields in the form.
TotalMarks
(
type = formula
value = English + Arts
)
|
But one formula field cannot be used in another formula field i.e.
The following code is invalid, because the formula field TotalMarks
is used in another formula field AverageMarks.
TotalMarks
(
type = formula
value = English + Arts
)
AverageMarks
(
type = formula
value = TotalMarks / 2
)
|
Note: |
Since formula fields are calculated, they do not get
displayed in the form when it is rendered. User can choose to view
these fields in the form view. |
Complete Sample
application "Student marks database"
{
page "Enter marks"
{
form Students_Mark_Sheet
{
displayname = "Students Mark Sheet"
Student_Name
(
displayname = "Student Name"
type = text
)
English
(
type = number
decimalplace = 2
)
Arts
(
type = number
decimalplace = 2
)
TotalMarks
(
type = formula
value = English + Arts
)
AverageMarks
(
type = formula
value = (English + Arts) / 2
)
}
list "View student marks"
{
Students_Mark_Sheet
}
}
}
|
Note: |
- All types of form fields except multiple select fields can
be used in formulas.
- The operators/functions that can be used in formulas can
be found in the sections Operators
and Built-in functions.
- The formulas will get recalculated when,
- the formula is modified
- the values of the fields participating in the formula
gets modified (when a record is updated).
|
Related Links:
Tips & Tricks - Date
Calculations and Formulas
Tips & Tricks - Updating
Field Values
|