Validation methods
AL includes a number of utility methods that are designed to facilitate data validation or initialization. Some of these methods are as follows:
TestField
FieldError
Init
Validate
We will discuss these methods more in the following sections.
TestField method
The TestField
method is widely used in standard Business Central code. With TestField
, we can test a table field value and generate an error message in a single statement if the test fails. The syntax is as follows:
Record.TestField(Field[, Value]);
If Value
is specified and the field does not equal that value, the process terminates with an error condition, and an error message is issued.
If no Value
is specified, the field contents are checked for values of zero or blank. If the field is zero or blank, then an error message is issued.
The advantage of TestField
is ease of use and consistency in code and in the message displayed. The disadvantage is that the error...