- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the TestField function
With the TestField function, you can check if a field has a value or if it is blank. If the field is empty, the TestField function will generate a run-time error.
customer.TestField("Salesperson Code");
You can also use the TestField function to test whether a field contains a specific value or not. If it doesn't, the function will generate an error. In the following example, the TestField function will check if the Salesperson Code contains the value ZX. The value is set to DK, so this should generate an error.
customer."Salesperson Code" := 'DK'; customer.TestField("Salesperson Code", 'ZX');
When the function generates an error, it will produce a multilanguage error with the translated Caption property of that field.
The TestField function is often used in the OnInsert trigger of master and document tables. These functions test if a number series is configured within the setup table before assigning a new number to the record based on a number series. The following example shows how these functions are programmed for the Customer table.
trigger OnInsert() begin if "No." = '' then begin SalesSetup.Get(); SalesSetup.TestField("Customer Nos."); NoSeriesMgt.InitSeries(SalesSetup."Customer Nos.", xRec."No. Series", 0D, "No.", "No. Series"); end;