FieldRef.FieldError([String]) Method
Version: Available or changed with runtime version 1.0.
Stops the execution of the code, causing a run-time error, and creates an error message for a field.
Syntax
FieldRef.FieldError([Text: String])
Parameters
FieldRef
Type: FieldRef
An instance of the FieldRef data type.
[Optional] Text
Type: String
Use this optional parameter to include the text of the error message. If this parameter is not present, default text will be used.
Remarks
Similar to a run-time error, this method causes any transaction to be ended automatically.
This method is like the FieldError Method for the Record data type. For examples, see FieldError Method (Record).
Example
The following example opens table 18 (Customer) as a RecordRef variable that is named CustomerRecref. The CustomerName variable is initialized with a blank text. CustomerRecref.Field
creates a FieldRef that is named MyFieldRef for field1 (No.) and selects record 30000. Field 2 (Name) is then selected for record 30000. If the CustomerName variable is a blank text, then MyFieldRef.FieldError
is executed and an error message is displayed. The text in Text000 text constant is inserted into the error message that is displayed by Dynamics 365.
var
MyFieldRef: FieldRef;
CustomerRecref: RecordRef;
CustomerName: Text;
Text000: Label 'cannot be blank';
begin
CustomerRecref.Open(18);
CustomerName := '';
MyFieldRef := CustomerRecref.Field(1);
MyFieldRef.Value('30000');
MyFieldRef := CustomerRecref.Field(2);
if CustomerName = '' then
MyFieldRef.FieldError(Text000)
else
//Do some processing
end;
This code example displays the following error message:
Name cannot be blank in Customer No.="30000".
Programming Guidelines
We recommend the following guidelines for error messages:
- 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 text constant for the Text parameter.
For more information, see Progress Windows, Message, Error, and Confirm Methods.
See Also
FieldRef Data Type
Get Started with AL
Developing Extensions
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for