Validating Data #1: User Input

Having seen a couple of posts on data validation coming by I decided to tackle this issue in a couple of blogs of which this one is the first. Just to straighten out me thoughts and knowledge on this, and share it with you.

User Input

Like in any other software system NAV will validate data, entered by a user, before it will allow it to be recorded in the database. This validation process is triggered, once a field has been populated and the user leaves the field. This might be for example by:

  • pressing the Enter key
  • using one of the arrow keys or PageUp/PageDown
  • pressing the mouse on another field, control or window

In NAV data validation can be seen as a three step process in the following order.

Step 1 – System Validation

Based on the properties of the field the system will check whether the data entered complies to each property. As an example let’s take the Quantity field on a Sales Invoice.

One of the main properties of any field that will be validated is the Data Type property. Being Decimal for our Quantity field this means that only decimal data can be entered into this field and any deviation from that should lead to an error thrown by the system. Like typing the text error in this field:

Step 2 – Field Validation

Next to system validation, i.e. checking the data entered against default properties of the field, a NAV developer has the possibility of programming additional checks and actions on any field. This is done by writing C/AL code on the OnValidate trigger of the relevant field.

As in the example of the Quantity field we see that quite some code has been written (even more than shown in this screen shot).

Step 3 – Control Validation

A third and last level of data validation is given on the UI (user interface), being the OnValidate trigger on to the form control Quantity field:

In case of our Quantity field no validation code has been provided on the UI. Note, however, that action will be taken based on code in the OnAfterValidate trigger after validation as discussed in this post.

Notes

  • Not all properties, like Name and Caption, are properties that lead to some kind of validation.
  • Checking of table relations based on the settings of the TableRelation and ValidateTableRelation properties is part of the system validation.
  • Maybe needles to mention, but OnValidate code is always executed after the system validation, where as the OnValidate trigger of the control is always fired after the OnValidate trigger of the linked field.
  • The OnValidate trigger is one of the main interfaces to program business logic defined for a field.

More Information

One Comment

  1. Pingback: Validating Data #5: Data- and XMLports – Van Vugt's DynamiXs

Leave a Reply

Your email address will not be published. Required fields are marked *