The TESTFIELD function is widely used in standard Business Central code. With TESTFIELD, we can test a variable 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 the error message is not as informative as a careful developer would provide.
The following screenshot of the TESTFIELD function usage is from Table 18 - Customer. This code checks to make sure that the Sales Order field's Status is equal to the option value Open before allowing the value of the Sell-to Customer...