TESTFIELD Function (FieldRef)

Determines whether the contents of a field matches a given value. If the contents differ from the given value, an error message is displayed.




Type: FieldRef

Refers to the current field.

Type: any

The value that you want to compare with the contents of the field referred to by

FieldRef. The data type of Value must match the type of the field.

If you include Value and the contents of the field do not match, an error message is displayed.

If you omit Value and the content of the field is zero or blank (empty string), an error message is displayed.


This function is like the TESTFIELD Function (Record) function.


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 Function (FieldRef, TestPage Field) sets the No. field to a blank text. The TESTFIELD function determines whether the contents of the field match 10000, the specified value. In this case, the content does not match so the Dynamics NAV throws an exception. If the there is a match, no exception is thrown. This example requires that you create the following variables in the C/AL Globals windows.

Variable name DataType
CustomerRecref RecordRef
MyFieldRef FieldRef
MyFieldRef := CustomerRecref.FIELD(1);  
MyFieldRef.VALUE := '';  

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

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


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

No. must be equal to 10000 in Customer: No.=AAA10000. Current value is ‘AAA10000’.

MyFieldRef := CustomerRecref.FIELD(1);  
MyFieldRef.VALUE := 'AAA 10000';  

See Also

FieldRef Data Type