ErrorInfo.AddAction(Text, Integer, Text) Method
Version: Available or changed with runtime version 11.0.
Specifies an action for the error.
Syntax
ErrorInfo.AddAction(Caption: Text, CodeunitID: Integer, MethodName: Text)
Parameters
ErrorInfo
Type: ErrorInfo
An instance of the ErrorInfo data type.
Caption
Type: Text
The text string that appears as the caption of the action in the error UI. The string can be a label that is enabled for multilanguage functionality.
CodeunitID
Type: Integer
The ID of the Codeunit to run when the action is initiated from the error UI. The codeunit should contain at least one global method to be called by the error action. The global method must have an ErrorInfo data type parameter for accepting the ErrorInfo object.
MethodName
Type: Text
The name of the method in the Codeunit, which is specified by the CodeunitID parameter, that you want to run for the action.
Remarks
The AddAction method accepts four parameters:
- Caption, which is the text string that appears as the caption of the action in the error UI.
- CodeunitID, which is the ID of the codeunit to run when the action is initiated from the error UI. The codeunit should contain at least one global method to be called by the error action. The global method must have an ErrorInfo data type parameter for accepting the ErrorInfo object.
- Method Name, which is the name of the method in the codeunit specified by the CodeunitID parameter, that you want to run for the action.
- Tooltip, which is the text string that appears as the tooltip of the action in the error UI.
If you call ErrorInfo.AddAction
and codeunit exists with the provided CodeunitID or no method called MethodName exists in that codeunit, then a runtime error occurs.
If possible, call ErrorInfo.AddAction
using Codeunit::CodeunitName and not the literal integer for the object ID of the codeunit. If there is a renumbering of the codeunit or if the codeunit was removed, then you get a compile-time error and not a runtime error.
Example
In the following example from the Business Central base app, you can see how an error message can be annotated with actions that the user can do to get unblocked.
procedure PreventModifyRecIfOpenApprovalEntryExistForCurrentUser(Variant: Variant)
var
WorkflowWebhookMgt: Codeunit "Workflow Webhook Management";
RecRef: RecordRef;
ErrInfo: ErrorInfo;
RejectApprovalRequestLbl: Label 'Reject approval';
ShowCommentsLbl: Label 'Show comments';
RejectApprovalRequestToolTipLbl: Label 'Reject approval request';
ShowCommentsToolTipLbl: Label 'Show approval comments';
begin
RecRef.GetTable(Variant);
if HasOpenApprovalEntriesForCurrentUser(RecRef.RecordId) or WorkflowWebhookMgt.HasPendingWorkflowWebhookEntryByRecordId(RecRef.RecordId) then begin
ErrInfo.ErrorType(ErrorType::Client);
ErrInfo.Verbosity(Verbosity::Error);
ErrInfo.Message(PreventModifyRecordWithOpenApprovalEntryMsg);
ErrInfo.TableId(RecRef.Number);
ErrInfo.RecordId(RecRef.RecordId);
ErrInfo.AddAction(RejectApprovalRequestLbl, Codeunit::"Approvals Mgmt.", 'RejectApprovalRequest', RejectApprovalRequestToolTipLbl);
ErrInfo.AddAction(ShowCommentsLbl, Codeunit::"Approvals Mgmt.", 'ShowApprovalCommentLinesForJournal', ShowCommentsToolTipLbl);
Error(ErrInfo);
end;
end;
To see a different code example with an error dialog with a Fix-it action, see Error messages with Show-it actions.
Related information
ErrorInfo Data Type
Actionable errors
Error handling
Getting Started with AL
Developing Extensions