Validate calculated fields

You can run validation to ensure that a calculated value is correct.

A calculated field obtains its value from one or more independent fields. For example, on the TravelDocs air ticket, the total cost equals the airfare plus taxes and fees.

In the air ticket example, you can use validation to ensure that the total cost is correct, based on the airfare and tax fields. An error does not necessarily mean that the value was calculated incorrectly on the original page. It might mean that one of the values was recognized incorrectly. You can change the status of the page, which contains the data that failed validation. This change ensures that the page is displayed to an operator for verification.

The Validations actions library includes a CalculateFields action completes arithmetic operations on number field values.

Library Action Description
Validations CalculateFields Returns True if the arithmetic expression is valid; returns False otherwise.

The following example returns True if the total cost equals the airfare plus taxes.

CalculateFields("'Total_Cost' = 'Airfare' + 'Taxes'")

The fields that you reference must contain number data. Otherwise, the action fails.

Because a calculation involves multiple field values, and because the CalculateFields action operates only on child objects, you cannot complete the calculation at the field level. Instead, you must complete the calculation at the page level.

Important: You can complete calculations on values from different pages or different documents within the batch. To do so, you must use variables.

When to do validation on calculated fields

The CalculateFields action works only on number fields. If your Validation rule set includes rules to validate and possibly correct the format of individual fields (for example, removing a USD suffix from a currency field). You must run the page-level validation after you completed all field-level validations. For example, an airline ticket has an associated series of fields. You can validate this associated series of fields in sequence before a full page-level validation by using the Close element of the page.
  • Air_Ticket
  • Open
    • Item Cost
      • Open
      • (global)
        • Validate: Validate Currency field
      • Close
    • Taxes
      • Open
      • (global)
        • Validate: Validate Currency field
      • Close
    • Total Cost
      • Open
      • (global)
        • Validate: Validate Currency field
      • Close
  • Close
  • (global)
    • Validate: Validate Total Cost

The Validate Total Cost rule runs after Datacap finishes processing all of the child fields on the page.