FIELDERROR
Another function very similar to the TESTFIELD
function is FIELDERROR
. But where TESTFIELD
performs a test and terminates with either an error or an OK result, FIELDERROR
presumes that the test was already performed and the field failed the test. FIELDERROR
is designed to display an error message, then terminate the process. This approach is followed in much of the NAV logic, especially in the Posting Codeunits (for example, Codeunits 12, 80, 90). The syntax is as follows:
TableName.FIELDERROR(FieldName[,OptionalMsgText]);
If we include our own message text by defining a Text Constant in the C/AL Globals | Text Constants tab (so the code can be multilingual), we will have:
Text001 must be greater than Start Time
Then we can reference the Text Constant in code:
IF Rec."End Time" <= "Start Time" THEN Rec.FIELDERROR("End Time",Text001);
The result is an error message from FIELDERROR
like that shown in the following screenshot:
An error...