The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
FIELDERROR Method (FieldRef)
Stops the execution of the code, causing a run-time error, and creates an error message for a field.
Refers to the field for which you want to create an error message.
Type: Text or Code
Use this optional parameter to include the text of the error message. If this parameter is not present, default text will be used.
Similar to a run-time error, this method causes any transaction to be aborted automatically.
This method is like the FIELDERROR Method for the Record data type. For examples, see FIELDERROR Method (Record).
The following example opens table 18 (Customer) as a RecordRef variable that is named CustomerRecref. The CustomerName variable is initialized with a blank text.
CustomerRecref.FIELD creates a FieldRef that is named MyFieldRef for field1 (No.) and selects record 30000. Field 2 (Name) is then selected for record 30000. If the CustomerName variable is a blank text, then
MyFieldRef.FIELDERROR is executed and an error message is displayed. The text in Text000 text constant is inserted into the error message that is displayed by Dynamics 365. This example uses the default error message. This example requires that you create the following global variables and text constants.
|Text constant||ENU value|
|Text000||cannot be blank|
CustomerRecref.OPEN(18); CustomerName := ''; MyFieldRef := CustomerRecref.FIELD(1); MyFieldRef.VALUE('30000'); MyFieldRef := CustomerRecref.FIELD(2); IF CustomerName = '' THEN MyFieldRef.FIELDERROR(Text000) ELSE //Do some processing
This code example displays the following error message:
Name cannot be blank in Customer No.=”30000”.
We recommend the following guidelines for error messages:
Describe what is wrong and how to solve the problem.
Write a short descriptive message. Do not use more words than necessary.
Note that a period is automatically inserted at the end of a FIELDERROR.
Use a text constant for the Text parameter.
For more information, see Progress Windows, MESSAGE, ERROR, and CONFIRM Methods.