FieldRef.TestField() Method

Version: Available or changed with runtime version 1.0.

Tests that the content of the field is not zero or blank (empty string). If it is, an error message is displayed.

Syntax

 FieldRef.TestField()

Parameters

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

Remarks

This method is like the TestField Method (Record) method.

Example 1

The following example opens the Customer table as a RecordRef variable that is named CustomerRecref, created a reference to the first field (No) and stores the reference in the MyFieldRef variable. The Value Method (FieldRef, TestPage Field) sets the No. field to a blank text. The TestField method determines whether the contents of the field match 10000, the specified value. In this case, the content does not match so the Dynamics 365 throws an exception. If the there is a match, no exception is thrown.

var
    MyFieldRef: FieldRef;
    CustomerRecref: RecordRef;
begin
    CustomerRecref.Open(Database::Customer);  
    MyFieldRef := CustomerRecref.Field(1);  
    MyFieldRef.Value := '';  
    MyFieldRef.TestField('10000');  
end;

In this example, the Dynamics 365 displays following error message:

No. must be equal to 10000 in Customer: No.=. Current value is ''.

Example 2

If the value of the No. field is set to a value other than 10000, Dynamics 365 displays the following error message:

No. must be equal to 10000 in Customer: No.=AAA10000. Current value is 'AAA 10000'.

CustomerRecref.Open(DataBase::Customer);  
MyFieldRef := CustomerRecref.Field(1);  
MyFieldRef.Value := 'AAA 10000';  
MyFieldRef.TestField('10000');  

FieldRef Data Type
Get Started with AL
Developing Extensions