Use Error with ErrorInfo or Label instead of Text
When the Error method is called in Business Central, the platform emits an RT0030 telemetry signal to Azure Application Insights. The alErrorMessage dimension of that signal carries the actual error text — but only when the first argument is a Label, TextConst, or ErrorInfo:
The actual error string from AL code is shown in this dimension only if the string is a
LabelorTextConstdata type. For all other data types, the stringUse ERROR with a text constant to improve telemetry detailsis shown instead of the actual string.— Analyzing Error method telemetry on Microsoft Learn
Passing a string literal, a Text variable, or a StrSubstNo expression strips the real message from telemetry. When you investigate errors in Application Insights, all you see is the generic placeholder — making it impossible to diagnose the issue without reproducing it.
Pass a Label variable directly to Error, or use an ErrorInfo
object.
Example
The following code passes a string literal to Error:
procedure ValidateAmount(Amount: Decimal)
begin
if Amount < 0 then
Error('Amount cannot be negative'); // Use Error with ErrorInfo or Label instead of Text [LC0048]
end;Declare the message as a Label variable and pass it to Error:
procedure ValidateAmount(Amount: Decimal)
var
AmountCannotBeNegativeErr: Label 'Amount cannot be negative';
begin
if Amount < 0 then
Error(AmountCannotBeNegativeErr);
end;A common mistake is wrapping a Label in StrSubstNo before passing it to Error. Because StrSubstNo returns Text, the message is still stripped from telemetry — even though the format string is a Label:
procedure ValidateCustomer(Customer: Record Customer)
var
NotValidCustomerErr: Label '%1 is not a valid customer.';
begin
if not Customer.Find() then
Error(StrSubstNo(NotValidCustomerErr, Customer.Name)); // Use Error with ErrorInfo or Label instead of Text [LC0048]
end;Error has built-in placeholder substitution — pass the Label and its arguments directly:
procedure ValidateCustomer(Customer: Record Customer)
var
NotValidCustomerErr: Label '%1 is not a valid customer.';
begin
if not Customer.Find() then
Error(NotValidCustomerErr, Customer.Name);
end;As an alternative, pass an ErrorInfo
object. Use Label for straightforward error messages; use ErrorInfo when you need actionable errors
, custom dimensions, or data classification:
procedure HandleError()
var
MyErrorInfo: ErrorInfo;
begin
if not TryDoSomething() then begin
MyErrorInfo := ErrorInfo.Create(GetLastErrorText());
Error(MyErrorInfo);
end;
end;When the diagnostic is reported
- The first argument to
Erroris a string literal (e.g.,Error('message')). - The first argument is a
Textvariable. - The first argument is a
StrSubstNoexpression, even when its format string is aLabel.
Error('') (empty string literal) does not trigger the diagnostic.
See also
- Dialog.Error(ErrorInfo) Method on Microsoft Learn
- Dialog.Error(Text, Any, …) Method on Microsoft Learn
- 3 Ways To Handle Errors In Business Central by Business Central Geek
- Dynamics 365 Business Central: changing the way of throwing Errors by Stefano Demiliani