Calculated fields
Calculated fields
You can use calculated fields, also known as formula tabs, to apply a formula to user input from other tabs and to display a calculated final result. If the values of the tabs providing input to the calculated field change, the value of the calculated field will also change.
Calculated fields have a type of formulaTab, and can draw their input from number fields, dateTabs, and dateSignedTabs. A calculated field must draw its input exclusively from number fields or dateTabs/dateSignedTabs; it cannot accept both numeric and date values at the same time.
Numeric formulas
To set the numeric formula of a calculated field, and to specify its inputs, you set its formula property and enter the mathematical formula to be used, specifying the tabLabels of the inputTabs to be used as variables.
For example, the following code demonstrates how to use a numeric formula to calculate the total price of an object by adding the amount of tax. The subtotal is entered in one tab, and another read-only tab supplies the tax rate.
Date formulas
You can perform date-time operations and create formulas using a set of predefined date functions. You can use the following date-related functions to create date formulas:
AddDays(d1,n1): Returns a date calculated by adding or subtracting a number of days (n1) to or from a date (d1). To subtract, a minus sign (-) is used before (n1).AddMonths(d1,n1): Returns a date calculated by adding or subtracting a number of months (n1) to or from a date (d1). To subtract, a minus sign (-) is used before (n1).AddYears(d1,n1): Returns a date calculated by adding or subtracting a number of years (n1) to or from a date (d1). To subtract, a minus sign (-) is used before (n1).DateDiff(d1,d2): Calculates the number of days between two dates (d1-d2).Day(d): Returns the current day of the month as a value, 1 through 31.Days(d): Returns the number of days in the month for the specified date field (d).
For example, if you had a contract that will be valid for 30 days, starting from the date the document is signed, you could use the following tabs definition to calculate the contract expiration date using the AddDays(d1,n1) function: