Using the Data Designer
Calculated Field ( )
Use a calculated field to perform a calculation based on values in other fields. For example, if your screen collects mortgage information, you could create one field to collect the mortgage and interest payment and another to collect taxes and insurance. The calculated field could sum those two numbers and display the monthly payment.
You can validate a calculated field. For example, you can require a positive number between 100 and 1,000.
Calculated fields are display only -- users cannot edit them.
Important!If a field will be referenced in a calculation, use the validation feature to require a value for that field. This forces the user to enter a number to be used in the calculation.
Dialog Box
Fields on the Calculated Field Dialog
Field Description Name Enter the name of the field.Note that you cannot enter spaces nor most special characters (!@#$%^&*()+=<>,.:;'"{}[]\|`~) into this field.See Also: The Name Field's Default Value Indexed Check if you want to index this field. For more information, see "Indexing the Fields of a Data Design Document" in the Supporting the Data Designer chapter of the Developer Reference Guide.The Indexed field may or may not appear, depending on how your administrator has set up your system. Display name Enter the text that appears when a user hovers the cursor over this field. Calculation Use this area of the screen to define the calculation that this field will perform. Formula Enter the calculation that this field will perform. See Also: Using the Formula Field Select Field Click this button to select a field to reference in the calculation. For more information, see Using the Formula Field. Examples Click the down arrow to the right of this field to see examples of calculations you can perform. When you select an example, it is copied into the Formula field.
Your system administrator can customize the examples. Instructions are provided in "The <cmddsgcalc> Command" in the Data Designer chapter of the Developer Reference Guide.
See Also: Explanation of Examples Validation Select the kind of validation to apply to this field. Your choices are:
- No validation - the user's response is not checked
- Non-negative number (required) - the result of the calculation must be a positive number
- Custom - You can create custom validation. For more information, see Custom Validation.
If you assign to this field any value other than No validation, the field is surrounded by red dashes in Data Entry mode. If the user's response does not meet the validation criteria, the field remains surrounded by red dashes. Your system administrator determines if a user can save a screen with invalid data. Caption Enter text to describe this item on the data entry screen.After you insert this field onto the screen, you can use eWebEditPro+XML's formatting capabilities to modify its size, font, color, and other attributes.
Note: The Caption field only appears on this dialog when you create the Calculated field. If you later try to edit the field, the Caption field is not on the dialog. However, you can edit the Caption text within the editor.
Data StyleUsing the Formula Field
You can copy a sample calculation into the Formula field by clicking the Examples field and selecting an operation from the drop down list. For example, if you click on Examples Add two numbers (X+Y), {X}+{Y} appears in this field.
Next, replace the variables with fields on the screen. Be sure to select the curly brackets ({}) as well as the letter between them. Then, when the user enters data into those fields, the calculation is performed using the current field values.
If a calculated field tries to perform a numerical calculation with a value that is blank or contains letters, NaN appears in the field. (NaN stands for "not a number.")
If a calculated field tries to divide by zero, Infinity appears.
Warning!If the user does not replace all variables with a field or a number, when the content is validated, validation will fail.
To do this, follow these steps.
- Select the first variable to replace. To continue the example, select {X}.
- Click the Select Field button. A screen appears listing appropriate fields on the Data Design screen.
Warning!If a variable appears more than once in a formula (for example, {X} * number( {X} <= {Y} ) + {Y} * number( {X} > {Y}), you only need to replace the first occurrence it - eWebEditPro+XML will replace the subsequent occurrences for you.
- If an XML document contains several occurrences of a field that is referenced in a formula, the value is derived as follows:
- When using the XPath functions sum() and count(), all values with the field name are considered. For example, a document includes three books whose prices are $10, $20 and $30. In this case, sum's value is $60.
- When using all other functions, the first value is used. For example, a document includes three books whose prices are $10, $20 and $30. If a calculation formula refers to <price>, its value is $10.
- You can replace a variable with a number instead of a field. For example, replace {X} * {Y} with ../price * 1.15.
- The expression can be complex, such as (round(Field1 * 0.80) + (1 div Field2)) - 2.
- You can use a string expression that creates a text message. For example, to calculate a full name from its parts: concat( title, ' ', givenname, ' ', familyname), which could produce "Dr. Jonathan Smythe".
Referencing Other Calculated Fields
A calculated field can only reference other calculated fields that appear before it in a document. For example, a document collects a series of numbers.
- One calculated field counts the number of numbers.
- Another totals their values.
- A third computes the average by dividing the total by the count.
In this example, you must place the third field below or to the right of the first two fields. Calculated fields that are defined later in a document do not appear in the Select Field or Group dialog.
Explanation of Examples
The following table explains the standard examples that appear in the Examples drop-down list of the Calculated Field dialog. Note that your system administrator can customize the list, so it may not match what is below.