Editar

Compartilhar via


Record.FieldError(Any, ErrorInfo) Method

Version: Available or changed with runtime version 8.1.

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

Syntax

 Record.FieldError(Field: Any, ErrorInfo: ErrorInfo)

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.

ErrorInfo
 Type: ErrorInfo
Additional information to include in the error if the test fails.

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