Editar

Compartilhar via


Record.FieldError(Any [, Text]) Method

Version: Available or changed with runtime version 1.0.

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

Syntax

 Record.FieldError(Field: Any [, Text: Text])

Parameters

Record
 Type: Record
An instance of the Record data type.

Field
 Type: Any
The field for which you want to create an error message.

[Optional] Text
 Type: Text
Use this optional parameter to include the text of the error message. If you do not use this parameter, then default text is used as shown in the following examples. You can use backslashes (\) to break lines.

Remarks

Like a runtime error, this method causes the system to automatically end any transaction.

Programming guidelines

The following guidelines for error messages are recommended:

  • 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 label data type for the Text parameter.

For more information, see Progress Windows, Message, Error, and Confirm Methods.

Example 1

In the first example, there is no Text parameter and the field does not have a value.

var
    CustomerRec: Record Customer;

...
CustomerRec."No." := '';  
CustomerRec.FieldError("No.");  

The following message is displayed:

You must specify No. in Customer No.=''.

Example 2

In the next example, there is no Text parameter and the field has a value.

var
    CustomerRec: Record Customer;

...  
CustomerRec."No." := 'NEW 3500';  
CustomerRec.FieldError("No.");  

The following message is displayed:

No. must not be NEW 3500 in Customer No.='NEW 3500'.

Example 3

The third example uses a non-empty string as the Text parameter.

var
    CustomerRec: Record Customer;
    Text001: Label 'is not valid';

...
CustomerRec."No." := 'NEW 3500';  
CustomerRec.FieldError("No.", Text001);  

The following message is displayed:

No. is not valid in Customer No.='NEW 3500'.

Record Data Type Get Started with AL
Developing Extensions