FIELDERROR Function (FieldRef)

Stops the execution of the code, causing a run-time error, and creates an error message for a field.




Type: FieldRef

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 function causes any transaction to be aborted automatically.

This function is like the FIELDERROR Function for the Record data type. For examples, see FIELDERROR Function (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 NAV. This example uses the default error message. This example requires that you create the following variables and text constant in the C/AL Globals windows.

Variable name DataType
CustomerRecref RecordRef
MyFieldRef FieldRef
CustomerName Text
Text constant ENU value
Text000 cannot be blank

CustomerName := '';  
MyFieldRef := CustomerRecref.FIELD(1);  
MyFieldRef := CustomerRecref.FIELD(2);  
IF CustomerName = '' THEN  
  //Do some processing  

This code example displays the following error message:

Name cannot be blank in Customer No.=”30000”.

Programming Guidelines

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 Functions.

See Also

FieldRef Data Type