Validation functions
C/AL includes a number of utility functions designed to facilitate data validation or initialization. Some of these functions are:
TESTFIELD
FIELDERROR
INIT
VALIDATE
TESTFIELD
The TESTFIELD
function is widely used in standard NAV code. With TESTFIELD
, we can test a variable value and issue 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 contain that value, the process terminates with an error condition and the associated error message is issued.
If no Value
is specified, the condition evaluated is to check for field contents of zero or blank. If the field is zero or blank, this is an error.
The advantage of TESTFIELD
is ease of use and consistency in code and in the message displayed. The disadvantage is the error message is not as informative as we might provide as a careful developer.
The following screenshot of the TESTFIELD
usage is from Table 18 - Customer. This...