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. You can add, subtract, multiply or divide
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. In the below given sample, the field TotalMarks is of type formula.
TotalMarks
(
type = formula
value = English + Arts
)
|
English and Arts are the fields and they get generated as variables in deluge.
But one formula field cannot be used in another formula field.
i.e. The following code is invalid.
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. |
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:
|
Also refer FAQ -> Form Fields -> Formula fields.