VALIDATE Function (FieldRef)
Use this function to enter a new value into a field and have the new value validated by the properties and code that have been defined for that field.
Refers to the current field.
Type: must be compatible with the data type of the field referred to by the FieldRef.
The value to insert in the field.
If you omit NewValue, the function validates the current value.
This function is like the VALIDATE Function (Record).
The following example opens table 17 (G/L Entry) as a RecordRef that is named EntryRecref. The FINDFIRST Function (RecordRef) searches for the first record in the table. The FIELD Function (RecordRef) sets the field to 3, which is the G/L Account No. field. The VALIDATE function validates and inserts the specified value (1210) into the field. The MODIFY Function (RecordRef) modifies the table. A message that indicates the G/L Account No. field has changed is displayed. To show that the code in the OnValidate trigger is executed, design the G/L Entry table and add the following code to the G/L Account No. – OnValidate trigger:
MESSAGE('The OnValidate trigger is called.');
This example requires that you create the following variables and text constants in the C/AL Globals windows.
|Text000||The G/L Account No. for record %1 is %2.|
|Text001||The G/L Account No. for record %1 has changed to %2.|
EntryRecref.OPEN(17); IF EntryRecref.FINDFIRST THEN BEGIN MyFieldRef := EntryRecref.FIELD(3); MESSAGE(Text000, EntryRecref.RECORDID, MyFieldRef.VALUE); MyFieldRef.VALIDATE('1210'); EntryRecref.MODIFY; MESSAGE(Text001, EntryRecref.RECORDID, MyFieldRef.VALUE); END;