Examples: Calculating a value for a computed field
Combining text and field values to create a message
The SchedDisp field, which displays only when users read or print a document, can display two different messages depending on the value in the Sched field. If it is a special, temporary schedule, the message combines words with a text-based version of the value in the Date field. If the schedule is permanent, the message is "Regular schedule."
@If(Sched = "Special schedule"; "Special schedule for week starting: " + @Text(Date); "Regular schedule")
Totaling monthly budget figures
The MonthlyTotal field in the Budget form is a computed Numbers field that is formatted for Currency with two decimal places. The formula totals the values in each category to calculate the total budget.
Advertising + Entertainment + Miscellaneous + Overhead + Salaries + Travel
Subtracting, multiplying, and dividing in computed number fields
When you design a computed number field to subtract or multiply editable fields on a form, give each editable field a default value of zero.
When you design a computed number field to divide editable fields, give each editable field a default value of zero and use the following formula to perform division in the computed number field:
FIELD DivisorFieldName := DivisorFieldName;
@If(@IsNewDoc & !@IsDocBeingRecalculated; (DividendFieldName / (DivisorFieldName + 1));(DividendFieldName / DivisorFieldName))
Storing the date and time a document is created
Notes® automatically uses internal fields to store the date and time a document is created. To display this information, define a Time field that is computed-when-displayed, and then write this formula for it:
@Created;
The field is defined as computed-when-displayed, rather than computed, to avoid storing the creation date information twice.
Determining the normal work day age of a document
This field formula determines the age of a document in work days, based on a five-day work week. In the following example:
- DateCreated is a field containing the date when the document was created. The field's data type is Date/Time, and it is computed using the formula @Created.
- Currentdate is a field containing the current date of the document. The field data type is Date/Time, and it is computed using the formula @Now. Because Notes® sorts dates in seconds, you must divide by (seconds per minute) * (minutes per hour) * (hours in a day), which equals 86400.
- Weekend_days is a temporary variable that contains "Age of document
in days" divided by "Number of days in a week," multiplied by "Days
in a weekend."
temp := (@Date(Currentdate) - @Date(DateCreated)) / 86400; weekend_days := @Integer((temp / 7)) * 2; wkday := @Weekday(DateCreated); adjust := @If(((wkday + @Modulo(temp; 7) - 7) > 0); 2; 0); working_days := temp - (weekend_days + adjust); @If(Currentdate = ""; 0; working_days);