Usage:
This blog shows to use error messages in different ways possible.
If you’re developing App for AppSource and want to give more detailed error message plus advanced capabilities to solve the error by end-users on their own.
Use Cases with examples:
1. ErrorInfo.Create (not a data type but as a direct function)-
When used with Error() do not make any difference and will show below error.
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
begin
Error('App published: Hello world');
//OR
Error(ErrorInfo.Create('App published: Hello world'));
end;
}
2. ErrorInfo (as a data type with MessageType as Client)-
Purpose: To show the specific error message same as above use case and sends to telemetry.
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
begin
// Error(InitialMsg);
// Error(ErrorInfo.Create(InitialMsg));
InitializeClientError();
end;
local procedure InitializeClientError()
var
InitializeErrorInfo: ErrorInfo;
begin
InitializeErrorInfo.DataClassification(DataClassification::SystemMetadata);
InitializeErrorInfo.ErrorType(ErrorType::Client);
InitializeErrorInfo.Verbosity(Verbosity::Error);
InitializeErrorInfo.Message(InitialMsg);
Error(InitializeErrorInfo);
end;
var
InitialMsg: Label 'App published: Hello world';
}
Output: Same as case # 1.
3. ErrorInfo (as a data type with MessageType as Internal)-
Purpose: To show some generic error message same as above use case and sends to telemetry. Mainly for developers track this error message.
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
begin
InitializeInternalError();
end;
local procedure InitializeInternalError()
var
InitializeErrorInfo: ErrorInfo;
begin
InitializeErrorInfo.DataClassification(DataClassification::SystemMetadata);
InitializeErrorInfo.ErrorType(ErrorType::Internal);
InitializeErrorInfo.Verbosity(Verbosity::Error);
InitializeErrorInfo.Message(InitialMsg);
Error(InitializeErrorInfo);
end;
var
InitialMsg: Label 'App published: Hello world';
}
4. ErrorInfo (with Title)-
Purpose: To show some error message with a title.
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
begin
InitializeClientError();
end;
local procedure InitializeClientError()
var
InitializeErrorInfo: ErrorInfo;
ErrorTitleLbl: Label 'Initializing error.';
begin
InitializeErrorInfo.DataClassification(DataClassification::SystemMetadata);
InitializeErrorInfo.ErrorType(ErrorType::Client);
InitializeErrorInfo.Verbosity(Verbosity::Error);
InitializeErrorInfo.Message(InitialMsg);
InitializeErrorInfo.Title(ErrorTitleLbl);
Error(InitializeErrorInfo);
end;
var
InitialMsg: Label 'App published: Hello world';
}
5. ErrorInfo (with Action)-
Purpose: To show some error message with a action and title.
Code:
Add InitializeErrorInfo.AddAction(UpdateLbl, Codeunit::”Update MNK”, ‘UpdateOnCustomer’);
local procedure InitializeClientError()
var
InitializeErrorInfo: ErrorInfo;
ErrorTitleLbl: Label 'Initializing error.';
UpdateLbl: Label 'Make Update';
begin
InitializeErrorInfo.DataClassification(DataClassification::SystemMetadata);
InitializeErrorInfo.ErrorType(ErrorType::Client);
InitializeErrorInfo.Verbosity(Verbosity::Error);
InitializeErrorInfo.Message(InitialMsg);
InitializeErrorInfo.Title(ErrorTitleLbl);
InitializeErrorInfo.AddAction(UpdateLbl, Codeunit::"Update MNK", 'UpdateOnCustomer');
Error(InitializeErrorInfo);
end;
codeunit 50100 "Update MNK"
{
trigger OnRun()
begin
end;
procedure UpdateOnCustomer(ErrorInfo: ErrorInfo)
var
SomeProcessesLbl: Label 'Some process or data updates here.';
begin
Message(SomeProcessesLbl);
end;
}
6. ErrorInfo (with Navigation)-
Purpose: To show some error message with a navigation, action and title.
Code:
Add InitializeErrorInfo.AddAction(UpdateLbl, Codeunit::”Update MNK”, ‘UpdateOnCustomer’);
local procedure InitializeClientError()
var
InitializeErrorInfo: ErrorInfo;
ErrorTitleLbl: Label 'Initializing error.';
UpdateLbl: Label 'Make Update';
ActualUpdateLbl: Label 'Make Actual Update';
NavigateToCardLbl: Label 'Open Card';
begin
InitializeErrorInfo.DataClassification(DataClassification::SystemMetadata);
InitializeErrorInfo.ErrorType(ErrorType::Client);
InitializeErrorInfo.Verbosity(Verbosity::Error);
InitializeErrorInfo.Message(InitialMsg);
InitializeErrorInfo.Title(ErrorTitleLbl);
//Add actions using another codeunit
InitializeErrorInfo.AddAction(ActualUpdateLbl, Codeunit::"Update MNK", 'ActualUpdateCustomer');
//Add navigation action using another codeunit
Rec.FindFirst();
InitializeErrorInfo.PageNo(Page::"Customer Card");
InitializeErrorInfo.FieldNo(Rec.FieldNo(Blocked));
InitializeErrorInfo.RecordId(Rec.RecordId);
InitializeErrorInfo.AddNavigationAction(NavigateToCardLbl);
Error(InitializeErrorInfo);
end;
codeunit 50100 "Update MNK"
{
trigger OnRun()
begin
end;
procedure ActualUpdateCustomer(ErrorInfo: ErrorInfo)
var
Customer: Record Customer;
begin
Customer.FindFirst();
if Customer.Blocked = Customer.Blocked::" " then
Customer.validate(Blocked, Customer.Blocked::All)
else
Customer.validate(Blocked, Customer.Blocked::" ");
Customer.Modify();
end;
}
Important Notes:
You cannot have two actions at the same time.
Any actions you put should have reference to global function of that Codeunit.
Try other functions like DetailedMessage for Telemetry.
References:
[…] Source : LEARN = EXPERIENCE + ERROR + SOLUTIONS Read more… […]
LikeLike